views:

180

answers:

3

Hi, i'm using RESTFUL authentication on a rails application. The signup/login is working fine. I'm trying to display the username (based on what they logged in with) on the 'members' page they are re-directed to. for example, "Welcome back John!"

any ideas?

thanx

+1  A: 

Use the current_user method provided by RESTful Authentication.

Welcome back <%= current_user.name %>
John Topley
thanx. i tried this...@welcome_message = current_user (in the controller)and then <%= @welcome_message %> (in the view)but it doesn't display the welcome message. any thoughts? thanx
pixeltocode
i tried addind Welcome back <%= current_user.name %>but i getundefined local variable or method `current_user.name' for #<ActionView::Base:0x1042794f8>
pixeltocode
Replace `.name` with whatever attribute you're using to hold the user's name.
Eric Hill
+1  A: 

Put something like the following in your controller (assuming the session variable is :user_id):

@username = User.find(session[:user_id]).name

And then in your view use that variable:

Welcome back <%= @username %>
JRL
thanx. i tried that. i get undefined method `name' for #<User:0x104212028>how do i know what the session variable is? thanx
pixeltocode
@pixelcode: your message means you found a user, but that the User model does not have a method called name. You need to either provide a method called name, or use the existing column name (if it's 'login', use login).
JRL
A: 

thanx Veger, JRL, John and Eric. this fixed the problem.

in the controller flash[:message] = "welcome back ", current_user.login

and in the view <%= flash[:message] %>

pixeltocode