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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Shai Rosenfeld
2007-Nov-28 13:06 UTC
Re: Variable visible in all actions of the controller
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 helpwhy not use acts_as_authenticated? generally speaking, a session should suffice - that''s what most authentication systems use anyhow ;) session[:user].name or something like that hth, --shai -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 28, 2:06 pm, Shai Rosenfeld <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 ;) > > session[:user].name or something like that > > hth, > > --shai > -- > 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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Nov-28 14:21 UTC
Re: Variable visible in all actions of the controller
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Stefan Magnus Landrø
2007-Nov-28 14:42 UTC
Re: Variable visible in all actions of the controller
I guess you could write a helper method too, and use it in your view. On 28 Nov, 15:21, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---