rails many-to-many relationship with nested form link_to_add does not work -


i trying build complex form adding agendas, , use link_to_add helper dynamicaly add new users given agenda in form. using nested_form gem , accepts_nested_attributes_for method. these models:

class agenda < activerecord::base   has_many :roles   has_many :users, through: :roles   accepts_nested_attributes_for :roles    belongs_to :owner, class_name: user    attr_accessible :name,                   :address,                   :owner,                   :roles_attributes  end   class role < activerecord::base   belongs_to :agenda   belongs_to :user   accepts_nested_attributes_for :user    attr_accessible :agenda,                   :role,                   :user  end  class user < activerecord::base   has_many :roles   has_many :agendas, through: :roles end 

and controller:

class agendascontroller < applicationcontroller    ...    def new     @agenda = agenda.new     @role = @agenda.roles.build     @user = @role.build_user   end end 

and form:

<%= nested_form_for @agenda |f| %>   ....   <%= f.fields_for :roles |role_f| %>     <%= role_f.fields_for :user |user_f| %>       <div class="control-group">         <%= user_f.label :email, :class=>"control-label" %>         <div class="controls controls-row">           <%= user_f.text_field :email %>         </div>       </div>     <% end %>     <div class="control-group">       <%= role_f.label :role, :class=>"control-label" %>       <div class="controls controls-row">         <%= role_f.text_field :role %>       </div>     </div>     <%= role_f.link_to_remove "remove user" %>   <% end %>   <%= f.link_to_add "add new users", :roles %>  <% end %> 

and works fine, except link_to_add, not append fields_for :user block. how make link_to_add helper render whole fields_for :roles block fields_for :user block?

i'ved added new patch make this answer relvant newest version of nested_form. works me using this..


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -