Rails - adding nested attributes then validation fails, new nested attributes are not passed back to the :edit render
I have a Rails app with nested attributes. My MVC works great except when the nested validation fails. Here is my parent model controller:
def update
if @model.update(model_params)
respond_to do |format|
format.html { redirect_to @model, notice: 'Model was successfully updated.'}
end
else
render :edit
end
end
The issue is then in my model view when I build the nested form again:
<%= f.simple_fields_for :nested_model, @model.nested_model.joins(:related_model).order(:name) do |i| %>
I get all the original nested_model items in the form but the new ones that were passed in the params are not added. This works 100% when there are no validation issues. How do I add those invalid nested_model items back in here. I feel like there is an existing solution to this that I can't seem to find easily.