5

I am using rails 4 and nested forms and strong parameters.

I need to update multiple models from one form.

This is how I am declaring my strong parameters. From the Parent controller. The associations are has_many and belongs_to going in this order Rundatum->Material->ParticleSize

def rundatum_params
    params.require(:rundatum).permit( :material, :company_id, :material_density, :feed_moisture, :date, :building, :machine, :material_weight, :time_mins, :rate_lb_hr, :mill_amps, :class_amps, :mill_liner, :beater_plate_size, :mill_rpm, :class_rpm, :feeder_type, :feeder_setting, :feeder_aug_diameter, :tlgs_set, :air_pressure, :temp_mill_out, :temp_prod_out, :temp_ambient, 

    materials_attributes: [:id, :name, :density, :msds_url, :moisture, :notes, :_destroy], 

    particle_sizes_attributes: [:id, :screen, :percent_through, :percent_retained, :_destroy])
end

The output from the rails server is:

Rundatum Load (0.6ms)  SELECT  "rundata".* FROM "rundata"  WHERE "rundata"."id" = $1 LIMIT 1  [["id", 7]]

Unpermitted parameters: particle_sizes_attributes

What is the way to declare strong parameters when updating multiple models from one form?

Thanks

1 Answer 1

6

If you have ParticleSize nested within Material, then you should nest your parameters as well.

def rundatum_params
  params.require(:rundatum).permit( :material, :company_id, :material_density, :feed_moisture, :date, :building, :machine, :material_weight, :time_mins, :rate_lb_hr, :mill_amps, :class_amps, :mill_liner, :beater_plate_size, :mill_rpm, :class_rpm, :feeder_type, :feeder_setting, :feeder_aug_diameter, :tlgs_set, :air_pressure, :temp_mill_out, :temp_prod_out, :temp_ambient, 

  { materials_attributes: [:id, :name, :density, :msds_url, :moisture, :notes, :_destroy, 

  { particle_sizes_attributes: [:id, :screen, :percent_through, :percent_retained, :_destroy] }] })
end
Sign up to request clarification or add additional context in comments.

2 Comments

I think that this topic has the answer, Ill check tomorrow -> stackoverflow.com/questions/17569999/…
That is it! I am very surprised this is not easier to find on the internets. uides.rubyonrails.org should add this to there strong params example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.