pdfはそこにあります。を表示するPDF
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)}
私が説明と名前のsample.pdfがファイルのアップロードしたインスタンスを検索することができるように、私もgem 'friendly_id'
を使用しています。
そのページ(http://localhost:3000/documents/sample.pdf
)を入力するけれども、私が取得:
Missing template /document with {:locale=>[:en], :formats=>[:pdf], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}
は、私はそれが:formats=>[:pdf]
とは何かを持って推測しています。
私は<%= link_to "document", asset_path(document.file.url) %>
を作成するときに、私はこのリンクを取得:
http://localhost:3000/documents/sample.pdf
マイルートファイル:私はより多くのようになりたい
http://localhost:3000/Users/user/Desktop/testsite/documents/sample.pdf?1473447505
Rails.application.routes.draw do
resources :documents
root 'main_pages#home'
get 'home' => 'main_pages#home'
get '*path' => redirect('/')
end
私は私はこれについて正しいことをやっているのかどうかは分かりません。
どのような提案も素晴らしいでしょう。
あなたのルートファイルを共有できますか? –
@Udaykumardas私はあなたの質問にそれの要点を入れました。しかし、私は基本的に 'Document'というクラスにそのファイルを含めています。 'Document'は':name、:description、:file、 ':' slug'を持ちます。 :ファイルは 'assets/documents /'の場所にあるフォルダにアップロードされます。どこにpdfにアクセスしたいのですか?www.testsite.com/documents/sample.pdf – Corey