How would I handle a failure in that second piece? Can I put it in transaction and roll it back?
On Aug 29, 1:31 pm, Bill Walton <bwalton...@gmail.com> wrote: > Hi Chris, > > On Sun, Aug 29, 2010 at 12:24 PM, Chris <cdellin...@gmail.com> wrote: > > Sorry for the newbie question in advance... I've got three models, a > > user, site and user_site model. A site can have many users and a user > > can have many sites. The relationship between these two is stored in > > user_site. In my model defs user and sites both have has_many > > user_sites statement. Within my user_sites file, there are two > > belongs_to statements, one for user and one for site. within the What > > I'm looking to do is when a user is created initially to automatically > > create a record in user_site for a default site (I have it contained > > in an instance variable within the user controller). What I'm not > > sure is how to most effectively do this so that the generated id for > > user is automatically pulled into the child record in user_site, > > basically I'm trying to come up with an efficient method for creating > > the user and user_site records. Any guidance is much appreciated. > > Use an after_create filter in your User model to create and populate > the record in user_sites with the user_id. > > HTH, > Bill -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.