Hello all - I''m looking to create a form that would allow the editing of existing model instances while also allowing new model instances to be created. (its an order form where the model instances would be an order line item joining the order to an item) It looks like either one alone is easy, because in the former case the field names would be foo[id] where the id is from the database, and in the latter case, where the models are all new, it would be foo[index]. I''d like to add the new "empty" rows using some javascript which should be easy, I just don''t know how rails will approach the unsaved rows in this case. How does one mix these models? In my case, I can''t create new "empty" models for the new rows, because of some not null constraints in the database. How do other folks deal with situations like this? Thanks for any advice or comments -James --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> How does one mix these models? In my case, I can''t create new "empty" > models for the new rows, because of some not null constraints in the > database.Actually you can create a new "dummy" Model instance and pass it to the view. Because it has a bunch of blank fields in it, you cannot save it, but it can be used to create the form in the view. The "dummy object will disappear as soon as the view is finished rendering never having seen the database. When the user gets done filling in the form, they will hopefully have provided you with all the data you need to create another new instance of your model. This time you will be able to save it to the database (or complain to the user about missing data) The real trick here is distinguishing between a Form that is returning a new object and a form returning an updated existing object. There are a number of ways to do this and I don''t like any of them a lot so if you need help with this piece, asks someone with a stronger opinion. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Reasonably Related Threads
- form_for and Multiple Models Being Saved
- Validation dependent on unsaved parent
- Can I tell if the associated record is new in a belongs_to save?
- Best way to handle associated object creation WithIN the SAME form ?
- inverse_of breaks for unsaved child associations during save of parent