Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 0.71 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to Upload a multipage PDF with Paperclip?
  2. class Post < ActiveRecord::Base
  3.   belongs_to :Blogs
  4.  
  5.   attr_accessible :content, :title, :pdf
  6.  
  7.   has_attached_file :pdf,
  8.                     :url  => "/assets/products/:id/:style/:basename.:extension",
  9.                     :path => ":rails_root/public/assets/products/:id/:style/:basename.:extension"
  10.  
  11.   validates_attachment_content_type :pdf,
  12.       :content_type => [ 'application/pdf' ],
  13.       :message => "only pdf files are allowed"
  14. end
  15.        
  16. <%= form_for ([@post]), :html => { :multipart => true } do |f| %>
  17.        
  18. <p>
  19. <b> Name </b><br>
  20.     <%= f.file_field :pdf %>
  21. </p>
  22.        
  23. <p>
  24.   <%= image_tag @post.pdf.url(:original) %>
  25. </p>
  26.        
  27. <p>
  28.   <%= link_to 'My PDF', @post.pdf.url %>
  29. </p>