rails simple_nested_form_for fields_for wrong number of arguments

时间秒杀一切 提交于 2019-12-08 16:37:43

问题


So I'm building a form in rails 3.1, using

<%= simple_nested_form_for(@person, :url => collection_url, :html=>{:multipart => true}) do |f| %>
  <%= render :partial => "form", :locals => { :f => f } %>
<% end %>

but this line in the partial is causing the problem:

<h2>Badges</h2> 
<ul id="certifications">
// this following line is raising the error "wrong number of arguments (4 for 3)"
<%= f.fields_for :certifications do |certification_form| %> 
    <%= render :partial => 'certification', :locals => { :f => certification_form } %>
<% end %>
</ul>
<%= f.link_to_add "Add a Badge", :certifications %>

So here is the model:

class Person < ActiveRecord::Base
  has_many :certifications, :dependent=>:destroy, :order=>:position
  has_many :certificates, :through=>:certifications
  accepts_nested_attributes_for :certifications, :allow_destroy => true
end

The controller is using the inherited resource gem.

What's wrong? Thanks for the help.


回答1:


I was having the same problem until I realized the gem is out of date with the version on git. I just manually updated the gem files with the ones on git and problem fixed!




回答2:


imorsi is correct, here's how i did it:

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

I also removed and re-bundled the gem, but I suspect that was not necessary. don't forget to restart your server after gem installation.




回答3:


I tried that, but didnt work

So i ended up doing "bundle open nested_form" and copy pasted from github



来源:https://stackoverflow.com/questions/6655674/rails-simple-nested-form-for-fields-for-wrong-number-of-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!