有3个型号
Account
has_many organizations, dependent destroy
has_many people, dependent destroy
accepts_nested_attributes_for organizations
accepts_nested_attributes_for people
Organization
belongs_to account
has_many people, dependent destroy
accepts_nested_attributes for people
People
belongs_to account
belongs_to organization
所以,在新的帐户表格中。我有类似的东西......
<%= form_for(@account) do |f| %>
<%= f.fields_for :organizations do |builder| %>
<%= render 'organizations_fields', :f => builder %>
<% end %>
<%= f.fields_for :people do |builder| %>
<%= render 'people_fields', :f => builder %>
<% end %>
<div class="actions">
<%= f.submit 'Crear cuenta' %>
</div>
<% end %>
在accounts_controller.rb
中 def new
@account = Account.new
organization = @account.organizations.build
organization.people.build
...
def create
@account = Account.new(params[:account])
respond_to do |format|
if @account.save
....
所以一切正常......
问题是,人员表中的account_id列是零。我该如何修复?