Variable visible in all actions of the controller

Hi
I would like to have variable visible for all actions of one
controller. It’s something like admin panel where I have some actions,
such as ‘list’, ‘new’, ‘edit’ and I have to display at the top of the
page logged user’s name.
How and where do I have to declare and assign variable like this?

Thanks for help

Hipnotik wrote:

Hi
I would like to have variable visible for all actions of one
controller. It’s something like admin panel where I have some actions,
such as ‘list’, ‘new’, ‘edit’ and I have to display at the top of the
page logged user’s name.
How and where do I have to declare and assign variable like this?

Thanks for help

why not use acts_as_authenticated?

generally speaking, a session should suffice - that’s what most
authentication systems use anyhow :wink:

session[:user].name or something like that

hth,

–shai

On Nov 28, 2:06 pm, Shai R. [email protected]
wrote:

why not use acts_as_authenticated?
Posted viahttp://www.ruby-forum.com/.
I would like to not use additional plugins to do that.
It works on sessions, of course, and I know that I can put user_name
in session but I would like to keep only user_id and read other
information from database. But I don’t want to do something like:
@user_name = User.find_by_id(session[:user_id])
in every action. I would like to do that once per controller and use
it in all views available for these actions.
Is it correct and possible?

I guess you could write a helper method too, and use it in your view.

On 28 Nov 2007, at 13:57, Hipnotik wrote:

I would like to not use additional plugins to do that.
It works on sessions, of course, and I know that I can put user_name
in session but I would like to keep only user_id and read other
information from database. But I don’t want to do something like:
@user_name = User.find_by_id(session[:user_id])
in every action. I would like to do that once per controller and use
it in all views available for these actions.
Is it correct and possible?

A common solution is to use a before_filter

Fred