ruby on rails - Error: Unpermitted parameters with nested attributes -
i'm having problem saving contents of nested field. have 2 models incorporation
, company
. relate follows:
class company < activerecord::base belongs_to :incorporation end class incorporation < activerecord::base has_one :company accepts_nested_attributes_for :company end
my aim create new company
, incorporation
entry in same form, using both incorporations controller , view.
(problem) however, each time attempt submit form, incorporation entry goes through company entry held unpermitted parameters
error:
started post "/incorporations" 127.0.0.1 @ 2014-12-15 22:40:59 -0700 processing incorporationscontroller#create html parameters: {"utf8"=>"✓", "authenticity_token"=>"lcj/ztnne/9l/ualycna8eae8vmmn010tos4t5e+zka=", "incorporation"=>{"title"=>"test", "company"=>{"name"=>"test"}}, "button"=>""} unpermitted parameters: company completed 500 internal server error in 4ms
this particularly surprising beleive i've set strong params correctly. below controller.
class incorporationscontroller < applicationcontroller def index end def show end def new @incorporation = incorporation.new @company = company.new end def create @incorporation = incorporation.new(incorporation_params) if @incorporation.save redirect_to @incorporation, notice: "successfuly saved incorporation info." else render 'new' end end def edit end def show end private def incorporation_params params.require(:incorporation).permit(:title, company_attributes: [:name, :state_corp, :street, :city, :state, :zip, :outstanding_common_stock, :fiscal_year_end_month, :fiscal_year_end_day]) end end
the form partial i'm using follows:
<%= form_for @incorporation |f| %> <div class="panel-body"> <%= f.text_field :title, input_html: { class: 'form-control' } %> <h3>test</h3> <%= f.fields_for @company |company| %> <%= company.text_field :name, input_html: { class: 'form-control' } %> <% end =%> </div> <%= f.button :submit, class: "btn btn-primary" %> <% end =%>
any ideas appreciated.
the usual way above
controller
def new @incorporation = incorporation.new @company = @incorporation.build_company
and in view
<%= form_for @incorporation |f| %> <div class="panel-body"> <%= f.text_field :title, input_html: { class: 'form-control' } %> <h3>test</h3> <%= f.fields_for :company |company| %> <%= company.text_field :name, input_html: { class: 'form-control' } %> <% end =%> </div> <%= f.button :submit, class: "btn btn-primary" %> <% end %>
the rest fine.
Comments
Post a Comment