我正在尝试使用单一表单将数据存储在多个表中。
def account_params
params.require(:account).permit(:status,:display_name,
:acc_billing_address_attributes =>[
:first_name, :last_name])
end
我的问题是,当我尝试在表中存储数据时,数据成功存储在帐户表和acc_billing_addresses表中,空白数据存储在表中,错误为:Unpermitted parameter:acc_billing_address
这些值以参数形式检索。
在我的控制器中我有:
def create
@account = Account.new(account_params)
@account.build_acc_billing_address
end
我的模特是:
class Account < ApplicationRecord
has_one :acc_billing_address
accepts_nested_attributes_for :acc_billing_address
end
和
class AccBillingAddress < ApplicationRecord
belongs_to :account
end
这是我的表格
<%= form_for(:account, url: account_index_path) do |f| %>
<table border = "0", cellpadding = "10", cellspacing = "0">
<tbody>
<tr>
<b> Branding Options</b>
<td align = "left", height = "25"> Display Name</td>
<td align = "left">
<%= f.text_field :display_name%>
</td>
</tr>
</tbody>
</table>
<%= f.fields_for :acc_billing_address do |builder| %>
<tr>
<b> Billing Address </b>
<td align = "left", height = "25"> Contact First Name</td>
<td align = "left">
<%= builder.text_field :first_name %>
</td>
<td align = "left", height = "25"> parent id</td>
<td align = "left">
</td>
<td align = "left", height = "25"> Contact Last Name</td>
<td align = "left">
<%= builder.text_field :last_name %>
</td>
</tr>
<% end %>
<tr>
<td align = "left">
<%= f.submit "Submit" %>
</td>
</tr>
</tbody>
</table>
</td>
<% end %>