MaggotChild
2011-Mar-25 07:07 UTC
Edit With Nested Forms - Values Not Preserved Across Submit
When a nested form submitted to the create action contains missing data, the form is redisplayed and the nested values the user entered remain. When submitting the same nested form to the update action, the newly entered values remain for the parent record, but the child records revert back to their pre edit values. Here''s the form (from Rails Guides): <% form_for @customer do |customer_form| %> <div> <%= customer_form.label :name, ''Customer Name:'' %> <%= customer_form.text_field :name %> </div> <% customer_form.fields_for :orders do |order_form| %> <p> <div> <%= order_form.label :number, ''Order Number:'' %> <%= order_form.text_field :number %> </div> <% unless order_form.object.new_record? %> <div> <%= order_form.label :_delete, ''Remove:'' %> <%= order_form.check_box :_delete %> </div> <% end %> </p> <% end %> <%= customer_form.submit %> <% end %> It looks like this is a problem with accepts_nested_attributes_for. It loads and updates the records in the nested form, but when the form is redisplayed @customer.orders is loaded from the DB, squashing the changes by the nested attributes module. Is it possible to retain nested data across form redisplays to the update action? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
MaggotChild
2011-Mar-26 01:14 UTC
Re: Edit With Nested Forms - Values Not Preserved Across Submit
On Mar 25, 12:07 am, MaggotChild <hsomob1...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > Is it possible to retain nested data across form redisplays to the > update action?Anyone? The answer appears to be no, given the Rails Guides example and the Complex Forms Examples: github.com/alloy/complex-form-examples/tarball/ master. This is a big downside to using nested attributes with complex forms. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.