Basically, I have an Events model and an EventSets model. Events have EventSets (where applicable) so I can list and group them accordingly in the app (say, a set of Concerts in the Park events where each individual concert event has slightly different attributes, but most of the data are common to all events in that set).
I have the necessary associations in place so that I can designate an EventSet in Events#new.
In my EventSet model, I have a few columns of ‘default’ information (common location, common name, etc.) that I’d like to use to pre-populate fields in Events#new.
The EventSet for a new event is designated by a select field (which lists all EventSets, pulled from the EventSets table).
Is there a standard way of handling this in Rails 3 (w/ jQuery)? Or should I roll my own jQuery/AJAX fix to handle it? (I like to stick with the sensible defaults where appropriate.)
Edit for clarification: I’m trying to pre-populate form fields while still in the /events/new view before the form is submitted (as soon as an EventSet is selected). This is necessary because the EventSet-designated ‘defaults’ will often be overriden for a given Event… they’re just a starting point to save on input repetition for the user.
Use the after_initialize callback
You could also do something similar in the Controller.
EDIT
You’ll need to grab those fields via an ajax request
routes.rb
events_controller.rb
new.html.erb