I have a situation where one of my nested fields is being passed to parameters but is not being inserted into the table.
My model Company
has_one :incorporation
. Incorporation has, right now anyway, one field, nested into the Company
form as follows
<%= 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 %>
The new
and create
methods in the controller are as follows
def new
@user=current_user
@company = @user.companies.build
@incorporation = @company.build_incorporation
@action = "new"
@caction = "create"
@remote=false
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."
end
end
The problem is that when I select one of the radio buttons in the simple fields, the log shows that the data is sent to the parameters:
Parameters: {"utf8"=>"✓",..., "company"=>{..."incorporation_attributes"=>{"trademark_search"=>"0"}},...}
But it is NOT being Inserted into the table. Instead, a new entry is inserted but only with the company_id
, id
, created_at
and updated_at
, all of which are perfectly accurate. There are no invalid parameter errors or anything like that.
My strong params look like this:
def company_params
params.require(:company).permit(:id, :name,...,incorporation_attributes: [:title, :trademark_search, :user_id, :employee_stock_options, :final_submit, :submit, :_destroy],...)
end
So somehow the parameters are not linking up with the table insertion (if that makes sense). What might be going on here?
Thanks for any ideas.