Ruby on rails 带有嵌套表单link\u to\u add的rails多对多关系不起作用

Ruby on rails 带有嵌套表单link\u to\u add的rails多对多关系不起作用,ruby-on-rails,nested-forms,Ruby On Rails,Nested Forms,我正在尝试构建用于添加议程的复杂表单,我想使用link\u to\u add helper为表单中的给定议程动态添加新用户。使用nested\u formgem和接受方法的\u nested\u属性。这些是我的模型: class Agenda < ActiveRecord::Base has_many :roles has_many :users, through: :roles accepts_nested_attributes_for :roles belongs_t

我正在尝试构建用于添加议程的复杂表单,我想使用
link\u to\u add helper
为表单中的给定议程动态添加新用户。使用
nested\u form
gem和
接受
方法的\u nested\u属性。这些是我的模型:

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
课程议程
和我的控制器:

class AgendasController < ApplicationController

  ...

  def new
    @agenda = Agenda.new
    @role = @agenda.roles.build
    @user = @role.build_user
  end
end
class AgendasController
我的表格:

<%= nested_form_for @agenda do |f| %>
  ....
  <%= f.fields_for :roles do |role_f| %>
    <%= role_f.fields_for :user do |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 %>

....
“控制标签”%>
“控制标签”%>

除了link\u to\u add之外,一切都正常,它不会为:user
块追加
字段。如何使link_to_add helper为:roles
块呈现整个
字段,以及为:user
块呈现
字段?

我已经添加了一个新补丁,使其与嵌套表单的最新版本相关联。现在用这个对我有用