Try adding :id
to the :scenario_attributes
portion of your feature_params
method. You only have the description field and the ability to allow a destroy.
def feature_params
# added => before nested attributes
params.require(:feature).permit(:id, :title, :narrative, :price, :eta, scenarios_attributes => [:id, :description, :_destroy])
end
As @vinodadhikary suggested, you no longer need to check if feature is a new record, since Rails, specifically using the form_for
method, will do that for you.
Update:
You don't need to define if @feature.new_record? ... else
in your form. It will be taken care by Rails when you use form_for
. Rails checks if the action is going to be create
or update
based on object.persisted?
, so, you can update your form to:
= form_for [@project, @feature] do |f|
...
= f.fields_for :scenarios, @feature.scenarios.build do |builder|
= builder.label :description, "Scenario"
= builder.text_area :description, rows: "3", autocomplete: "off"