Rails 3: After_save create profile

I have a user model and a profile model that are tied together.

What I'd like to do is to create an user profile every time an user registers.

Here's what I have in the User model now:

 after_save :create_profile

  protected

  def create_profile
    @profile = current_user.build_profile(params[:profile])
    @profile.save
  end

However, it doesn't seem to work because current_user is not recognized, which makes sense, however, what's the way to fix this?

Thanks

Answers


self.profile.create(params[:profile])

For a has_one association:

self.create_profile(params[:profile])

has_many

self.profiles.create(params[:profile])


Need Your Help

Get multiple Root elements with XDocument

c# xml linq-to-xml

I have an XML file that looks like this:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.