How to overwrite devise user session attributes?

I'm using devise for authentication: In my user model I've do:

def name     "#{first_name} #{last_name}" end

to have a name method. After signed in successfully I can use current_user.name. I want to overwrite name method if the user is guest. That's the use case:

The guest user signed in successfully, now its name is, for example, "guest" " guest". current_user.name is guest guest. After signed in I present a form with a name input field and a surname input field. Submitting the form I want to overwrite the name value with input fields values. So if name and surname are: "newguest" "newguest" I want current_user.name have newguest newguest. There a way to do this? Thank you.

No ideas?

Save the new "names" in session or directly in a cookie.

Yes I want to save in session but how can access the session? user_session hash is empty.

session["foo"] = "bar"

Of course it's empty until you put something there :slight_smile:

Sorry but I don't undestand very well. In GitHub - heartcombo/devise: Flexible authentication solution for Rails with Warden. is said that user_session is an helper to access the session of the successfully signed in user. So after signed in I expect to find something in user_session so that I can change some of its values.

I don't know about devise's "user_session" offhand, but it doesn't really matter. You can put anything you want (within reason!) in session in your app.

session["guest_first_name"] = "Bob"

Whatever. Just try it.