Trying to show a pdf by linking to a URL of www.testsite.com/documents/sample.pdf
I'm using paperclip to upload the pdf, and can see that the pdf is there.
has_attached_file :file,
:url => ":rails_root/documents/:filename",
:path => ":rails_root/public/assets/documents/:id/:filename"
validates_attachment :file, :content_type => {:content_type => %w(image/jpeg image/jpg image/png application/pdf application/msword application/vnd.openxmlformats-officedocument.wordprocessingml.document)}
I'm also using the gem 'friendly_id'
so that I can search my uploaded instance of the sample.pdf file with the description and name.
When entering that page(http://localhost:3000/documents/sample.pdf
) though, I get:
Missing template /document with {:locale=>[:en], :formats=>[:pdf], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}
I'm guessing it has something to do with the :formats=>[:pdf]
.
When I create a <%= link_to "document", asset_path(document.file.url) %>
, I get this link:
http://localhost:3000/Users/user/Desktop/testsite/documents/sample.pdf?1473447505
Which I would like to be more like:
http://localhost:3000/documents/sample.pdf
My Routes file:
Rails.application.routes.draw do
resources :documents
root 'main_pages#home'
get 'home' => 'main_pages#home'
get '*path' => redirect('/')
end
I'm not sure if I'm going about this the right way at all.
Any suggestions would be great.