small medium large xlarge

Generic-user-small
24 Aug 2011, 03:44
Suryansh (2 posts)

Hey Guys!

So I am currently done with chapter 14 of the book, what I would like to know is how do I get the current user’s name to show up on the welcome screen. This isn’t one of the tasks that is done so far in the book and I’ve been searching online but have not come up with any solutions yet. Basically what I am trying to do is on the Admin Index page, I want the text to say ‘Welcome User’ and User being the current admin that is logged in. Could anyone please tell me how to do this?

Thanks!

Suryansh

Generic-user-small
28 Aug 2011, 19:49
Suryansh (2 posts)

I got it, it’s <%= User.find(session[:user_id]).name %> if anyone else wants it

Generic-user-small
31 Aug 2011, 10:22
karb (1 post)

It’s not ‘the rails way’ to put logic, in this case ActiveRecord methods, in your view. Better is assigning a ` @current_user = User.find(session[:user_id]) ` and accessing it in your view like ` <%= @current_user.name %> `

You must be logged in to comment