Ruby on rails Rails.build Association非工作Rails

Ruby on rails Rails.build Association非工作Rails,ruby-on-rails,ruby,Ruby On Rails,Ruby,我有一个用户模型,如下所示 class User < ActiveRecord::Base devise :database_authenticatable, :registerable has_many :company_users accepts_nested_attributes_for :company_users, :allow_destroy => true has_many :companies, :through => :company_use

我有一个
用户
模型,如下所示

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable
  has_many :company_users
  accepts_nested_attributes_for :company_users, :allow_destroy => true

  has_many :companies, :through => :company_users
  has_many :roles, :through => :company_users
end
class CompanyUser < ActiveRecord::Base
  belongs_to :user
  belongs_to :company
  belongs_to :role
end
我正试图建立如下协会,但似乎不起作用

  # GET /users/new
  def new
    @user = User.new
    @user.company_users.build
  end
查看文件如下:

<%= form_for(@user) do |f| %>
  <div class="field">
    <%= f.label :name %><br>
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :email %><br>
    <%= f.text_field :email %>
  </div>
  <h3>Companies and Roles</h3>
  <div class="field">
    <% f.fields_for :company_users do |cu| %>
       <p>
         <%= cu.label :company_id %>
         <%= cu.text_field :company_id%>
         <%= cu.label :role_id %>
         <%= cu.text_field :role_id %>
         <%= cu.check_box :_destroy %>
         <%= cu.label :_destroy, 'delete' %>
        </p>
     <% end %>
    <p>
       <%= f.submit 'Add to user', :name => "add_company_user" %>
       <%= f.submit 'Delete from user', :name => "remove_company_user" %>
    </p>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>



公司和角色

“添加公司用户”%> “删除公司用户”%>


我正在试图找出哪里出错。

您缺少一个
=
,因此
块的
字段\u不会呈现到页面中。换行

<% f.fields_for :company_users do |cu| %>


您缺少一个
=
,因此
块的
字段不会呈现到页面中。换行

<% f.fields_for :company_users do |cu| %>



您能发布生成的错误吗?@j-dexx嗯,没有错误。我在UI中看不到文本字段。如果建立了关联,它应该会出现。您能发布生成的错误吗?@j-dexx嗯,没有错误。我在UI中看不到文本字段。如果建立了关联,它应该会出现。谢谢@spickermann。。。该死,我想我现在应该小睡一会儿了:PThanks@spickermann。。。妈的,我想我现在应该小睡一会儿了:P