On 2011-10-11, at 11:23 AM, Nikhil Goyal wrote:

> I have user model and referral model. Referral model has user_id as
> field.
> 
> Now when a new user is created, I need to call referral#create as well
> and pass it the id of the newly generated user to user_id of referral
> model. How can I do that.

to answer what you said, in your User model, add the following

before_create :generate_referral

private
def generate_referral
  self.referrals.create! {referral_attributes}
end

There are better ways of solving this but I tried to convert your message into 
code in the most concise way possible
> -- 
> 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 [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
> 

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to