【发布时间】:2016-01-15 08:46:21
【问题描述】:
我遇到错误的情况
Unpermitted parameter: incorporation
但是我在强大的参数中列出了它:
def company_params
params.require(:company).permit(:id, :name, :employee_stock_options, :options_pool, :state_corp, :street, :city, :state, :zip, :_destroy,
incorporation_attributes: [:title, :trademark_search, :user_id, :employee_stock_options, :final_submit, :submit, :_destroy],
names_attributes: [:id, :name_string, :suffix, :approved, :snapshot, :company_id, :_destroy],
有一些问题可能会导致该问题:
有问题的控制器实际上是Incorporation 控制器。但是,您可能会注意到,我们使用它来创建父模型Company,即has_one :incorporation。我意识到这有点奇怪,但我有理由希望我的模型以这种方式构造并使用incorporations_controller 来实现。
因此,我的表单结构如下:
<%= simple_form_for @company, url: url_for(action: @caction, controller: 'incorporations'), html: {id:"incorporationform"}, remote: false, update: { success: "response", failure: "error"} do |company| %>
<%= company.simple_fields_for @incorporation do |f| %>
<div class="padded-fields">
<div class="form_subsection">
<%= f.input :trademark_search, as: :radio_buttons, label: 'Would you like us to do a trademark search and provide advice regarding any issues we identify in relation to the name you have selected?', input_html: { class: 'form-control radio radio-false' } %>
</div>
</div>
<% end %>
....
<% end %>
提前感谢您的任何见解
更新:我的new和create方法如下incorporations_controller
def new
@user=current_user
@company = @user.companies.build
@incorporation = @company.build_incorporation
@action = "new"
@caction = "create"
end
def create
@snapshot="incorporation"
@company = current_user.companies.build(company_params)
@incorporation = @company.build_incorporation
if @company.save
current_user.companies << @company
if params[:final_submit]
redirect_to incorporations_index_path
else
redirect_to edit_incorporation_path(@incorporation), notice: "Successfuly saved incorporation info."
end
else
render 'new', notice: "Something went wrong; form unable to be saved."
# render :nothing => true
end
end
更新 2:如果有帮助,以下是日志中的参数:
"company"=>{"names_attributes"=>{"145\2853672570"=>{"name_string"=>"test19", "suffix"=>"INC", "_destroy"=>"false"}}, "fiscal_year_end_month"=>"", "fiscal_year_end_day"=>"", "street"=>"", "city"=>"", "state"=>"", "zip"\=>"", "issued_common_stock"=>"10,000,000", "employee_stock_options"=>"false", "options_pool"=>"0", "incorporation"=>{"submit"=>"0"}}, "commit"=>"Save"}
我注意到(与其他嵌套属性不同)合并后没有 _attributes 行。这可能有什么意义吗?
更新3:我似乎也在公司表中创建了一个公司条目,并分配了适当的所有权。但是没有填写其他字段。
【问题讨论】:
-
incorporation未列在您的强参数中。再试一次。
标签: ruby-on-rails ruby-on-rails-4 strong-parameters