2015-04-30 48 views
2

我需要允许我的用户上传Word文档(.doc文件)到我的应用程序。图像和PDF的工作很好,但是当我尝试上传文档时,我得到:使用回形针将文档(DOC/DOCX)上传到Rails

undefined method `documents_path' 

这是我的Document.rb文件中的代码。

 validates :title, presence: true 
     validates :file, 
     attachment_content_type: { content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif", "application/pdf", 'application/msword','applicationvnd.ms-word','applicaiton/vnd.openxmlformats-officedocument.wordprocessingm1.document', 'text/plain']}, 
     attachment_size: { less_than: 5.megabytes } 

     has_attached_file :file, styles: { 
     thumb: '100x100>', 
     square: '200x200#', 
     medium: '350x350>', 
     pdf_preview: '600x600>'}, processors: [:thumbnail] 

这是我的观点:

<%= simple_form_for(@document, multipart: true) do |f| %> 
    <%= f.input :title, :label => "Name of Document" %> 
    <%= f.input :hotel_id %> 
    <%= f.file_field :file, :label => "Upload Document" %> 
    <%= f.submit 'Submit', :class => "btn btn-primary" %> 
    <% end %> 

我的路线:

resources :hotels do 
    resources :advertisers 
    resources :documents 
end 
+0

显示您的观点和routes.rb文件 – Yule

+0

@Yule增加的视图和路由到我的问题。 – ItsJoeTurner

回答

0

因为你通过@document,这是一个文档,导轨查找了documents_path的路线,这没有按因为你把它嵌套在旅馆里面。你需要指定酒店,以及:

<%= simple_form_for([@hotel, @document], multipart: true) do |f| %> 
    ... 

记得定义@hotel

+0

谢谢,但这不是问题。该文档绕过控制器中的“if @ document.save”操作,并落入else部分。有任何想法吗? PDF和IMG/GIF完美地工作。 – ItsJoeTurner

+0

如果没有看到控制器,我不可能发表评论。 – Yule