Ruby on Rails Dynamic Forms


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:

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.


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