On Mar 1, 2011, at 8:58 PM, Mark Sobkowicz wrote: > Wow. That really is automagical. So now I have a nested form. > > <customer> > (+) > > If I press (+), I get > > <customer> > <rental> (+) > > > and so on. I actually have nested "bill" and "payment" models under rental, > since I'd like to enter an initial deposit when the rental is created. > > But when is Rental#new_for_customer called? When I press +, it seems it is > not. Even before I press + there are hidden forms already there - + seems > to just make them visible. If I want to populate the rental form after I > enter some customer data, what could I do? Putting code into the controller > seems to have no effect. >
The controller's not involved in generating those forms - there's actually a hidden instance that's populated when the page renders, and pressing + clones that to create live input fields. All the records get created when the whole form is posted, but that happens in CustomerController#create. If you were really dead-set on doing this, I suppose you could hook up some JS to copy data from Customer fields to the template, but it's likely to get very complicated. One other thought: the data I'm guessing you want to copy is, I'm guessing, things like city/state. You could try adding a before_validation callback to the Rental model that fills in the values from the customer record if they aren't filled in on the form, but that's a potentially confusing UI (and I vaguely recall there's a gotcha with the order that nested models are saved, but I may be imagining things). > Alternatively, I could use a multistep "Wizard"-ish kind of pattern for > creating these things - it would just be cool to have them all on the same > page. Is there a way to combine these approaches? Use a multistep pattern, > but all on the same page? Or just *look* like its on the same page? I'd recommend a multi-step approach - it'll also be one less page to customize, as you'll always be using the same UI to enter rentals instead of (potentially) having the UI on Customer#new and one on Rental#new_for_customer. --Matt Jones -- You received this message because you are subscribed to the Google Groups "Hobo Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
