Ruby on Rails Dynamic Forms

03.15.2015

I needed to create a dynamic form where users can add additional fields to save additional properties onto a model. I followed the instructions on this RailsCast: http://railscasts.com/episodes/403-dynamic-forms

Everything worked fine except for one thing. I was on Rails 4 and I needed to add all of the nested attributes to the parameter white list. You also have to add the id and _destroy as permitted parameters for the remove link to work.

Example:

def product_params
  params.require(:product).permit(:name, fields_attributes: [:name, :field_type, :required, :id, :_destroy])
end