Nicolas Blanco
2008-Jan-21 11:37 UTC
A method accessible from all controllers and views ? How ?
Hi, I''ve got this method : def is_admin? @current_user && @current_user.admin == 1 end I want to be able to call this method from all my controllers and all my views. If I put this method in application_controller I can call it from all my controllers but none of my views. If I put this method in application_helper I can call it from all my views but none of my controllers. What is the best way? Thanks. Nicolas Blanco. -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jan-21 11:43 UTC
Re: A method accessible from all controllers and views ? How ?
On 21 Jan 2008, at 11:37, Nicolas Blanco wrote:> > Hi, > > I''ve got this method : > > def is_admin? > @current_user && @current_user.admin == 1 > end > > I want to be able to call this method from all my controllers and > all my > views. > If I put this method in application_controller I can call it from > all my > controllers but none of my views. > If I put this method in application_helper I can call it from all my > views but none of my controllers. >Put it in application.rb & then use helper_method ? Fred> What is the best way? > > Thanks. > Nicolas Blanco. > -- > 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 -~----------~----~----~----~------~----~------~--~---
Keynan Pratt
2008-Jan-21 11:49 UTC
Re: A method accessible from all controllers and views ? How
put it in the User model -- 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 -~----------~----~----~----~------~----~------~--~---
Keynan Pratt
2008-Jan-21 11:52 UTC
Re: A method accessible from all controllers and views ? How
you can also use a mix in. module X def is_admin end end class some_controller include X helper :x end -- 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 -~----------~----~----~----~------~----~------~--~---