controller - Unpermitted parameter in Rails 4 when submitted nested attributes, has_many associated form -


i have 2 models (lead has_many :quote_metals , accepts_nested_attributes_for :quote_metals , quote_metal belongs_to :lead).

i trying write information submitted in form different datatables. there should 1 lead , multiple (no exact number) of quote_metals. receiving error saying unpermitted parameter: quote_metal.

here parameters:

processing leadscontroller#create html   parameters: {"utf8"=>"✓", "authenticity_token"=>"h5ibi7teodffxrk91puydlr4umc9ehu5ar9ul2d0u4stfp68gv0wogb/i43ukga2mhjlwg1znbpelwulmmxrkw==", "lead"=>{"name"=>"biggie", "email"=>"test@test.com",...., "note"=>"asdf", "quote_metal"=>[{"metal"=>"iron", "weight"=>"1", "unit"=>"pounds"}, {"metal"=>"ore", "weight"=>"4", "unit"=>"kg"}]}, "commit"=>"submit"} 

here controller:

class leadscontroller < applicationcontroller        def index         @lead = lead.new         @quote_metal = @lead.quote_metals.build       end        def create         #raise params.inspect         @lead = lead.create!(lead_params)       end        def show       end   private      def lead_params       params.require(:lead).permit([:name, :email, :phone, :zip, :note, :method, quote_metals_attributes: [:id, :metal, :weight, :unit, :price]])     end  end 

here form:

<div class="container">   <div class="row">      <div class="col-md-6">        <%= form_for @lead, class: 'form-horizontal' |f| %>         <div class="form-group">           <%= f.label :name %>           <%= f.text_field :name, class: "form-control" %>         </div>          <div class="form-group">           <%= f.label :email %>           <%= f.email_field :email, class: "form-control" %>         </div>          <div class="form-group">           <%= f.label :phone %>           <%= f.telephone_field :phone, class: "form-control" %>         </div>          <div class="form-group">           <%= f.label :zip %>           <%= f.text_field :zip, class: "form-control" %>         </div>          <div class="form-group">             <%= f.label :method %><br>             <%= f.select :method, lead.methods.map { |k,v| [k.humanize, k] }, {},             class: "form-control", :required => true %>         </div>          <div class="form-group">           <%= f.label :notes %>           <%= f.text_area :note, class: "form-control" %>         </div>            <%= render :partial => "metallead", locals: {f: f} %>           <%= render :partial => "metallead", locals: {f: f} %>          <div class="form-group text-center">           <%= f.submit "submit" %>         </div>       <% end %>       </div>   </div> </div> 

and partial:

<%= f.fields_for 'quote_metal[]', @quote_metal |ff| %>             <div class="form-group">                   <%= ff.label :metal %><br>                   <%= ff.select :metal, quotemetal.metals.map { |k,v| [k.humanize, k] }, {},                   class: "form-control", :required => true %>             </div>           <!-- break -->               <div class="form-group">                   <%= ff.label :weight %><br>                   <%= ff.number_field :weight, :required => true, step: 0.1, min: 0.0,                   placeholder: '5.00', class: "form-control" %>               </div>           <!-- break -->                             <div class="form-group">                 <%= ff.label :unit %><br>                 <%= ff.select :unit, quotemetal.units.map { |k,v| [k.humanize, k] }, {},                 class: "form-control", :required => true %>             </div> <% end %> 

the lead model writing datatable. doing wrong causing quote_metal not write?

the error in line <%= f.fields_for 'quote_metal[]', @quote_metal |ff| %>. should be

<%= f.fields_for :quote_metals, @quote_metal |ff| %> 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -