6

我一直在爲這幾天苦苦掙扎,似乎無法弄清楚什麼是錯的。我正在嘗試將多態文件附件添加到型號Item,該型號屬於Location型號。nested_form gem錯誤:參數數量錯誤(4爲3)

resources :locations do 
    resources :items 
    post :sort 
end 

resources :items do 
    resources :assets #model for attachments 
end 

我跟着a tutorial究竟該用carrierwave和nested_form做:因爲我的路由定義。但是,在設置完所有內容後,請求Item型號的New動作時出現以下錯誤:wrong number of arguments (4 for 3)。它告訴我的錯誤是在這一觀點的第7行發生:

<%= nested_form_for [@location, @item], :html => { :multipart => true } do |f| %> 
    <p> 
    <%= f.label :name %><br /> 
    <%= f.text_field :name %> 
    </p> 

    <%= f.fields_for :assets do |a_form| %> ### LINE 7 #### 
    <p> 
     <%= a_form.label :file %><br /> 
     <%= a_form.file_field :file %> 
     <%= a_form.hidden_field :file_cache %> 
    </p> 
    <%= a_form.link_to_remove "Remove this attachment" %> 
    <% end %> 

    <%= f.link_to_add "Add attachment", :assets %> 
    <p><%= f.submit %></p> 
<% end %> 

如果我不使用nested_form寶石,然後用常規form_for開始就認爲,我沒有得到任何錯誤,我能夠成功連接單個文件到Item。我可以嘗試和沒有寶石,但(據我所知),nested_form會自動化一些功能,如刪除文件和生成Ajax添加新的附件。

我只是想知道是否有人遇到這個錯誤或知道我在做什麼錯誤,這是造成nested_form問題?我明白錯誤意味着什麼,只是不確定在哪裏/爲什麼會引入額外的參數。我非常感謝您提供的任何見解!

FYI我的dev的設置:軌(3.1.0,3.0.10),nested_form(0.1.1),carrierwave(0.5.7)

回答

15

爲了得到nested_form與導軌3.1的工作,我不得不從github中取出最新的內容,而不是使用寶石中的內容。在我的Gemfile中:

gem "nested_form", :git => "git://github.com/ryanb/nested_form.git" 
+0

謝謝!我無法相信這就是它的全部。我見過[這篇文章](http://stackoverflow.com/questions/6655674/rails-simple-nested-form-for-fields-for-wrong-number-of-arguments)其中評論提到的版本是的日期...但是我的版本號匹配和帖子是從七月,所以我認爲rubygems已經更新,我從來沒有再給它一個想法。再次感謝,感謝您的時間。你規則:) – Denny

相關問題