2010-12-29 13 views
1

Ich habe ein Benutzermodell und ein Profilmodell, die miteinander verbunden sind.Rails 3: After_save Profil erstellen

Was ich tun möchte, ist ein Benutzerprofil jedes Mal erstellen, wenn ein Benutzer registriert.

Hier ist, was ich in dem User-Modell habe jetzt:

after_save :create_profile 

    protected 

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

aber es scheint nicht, weil die Arbeit current_user nicht erkannt wird, was Sinn macht, aber was ist der Weg, dies zu beheben?

Dank

Antwort

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

Für eine has_one Verein:

self.create_profile (params [: Profil])

has_many

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

Verwandte Themen