I have a few small methods as part of my authorisation scheme, These mostly get used by controllers, but sometimes I want a template to call them too. For example, there are methods called is_editor?, is_author? and is_publisher? currently in application.rb. I am including/excluding elements for navigation in the user interface based upon these roles. Therefore I want one definition of these methods that "everyone" can use. Whats the right rails way to achieve this? Cheers, --Kip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Kip wrote:> I have a few small methods as part of my authorisation scheme, These > mostly get used by controllers, but sometimes I want a template to > call them too. > > For example, there are methods called is_editor?, is_author? and > is_publisher? currently in application.rb. > > I am including/excluding elements for navigation in the user interface > based upon these roles. Therefore I want one definition of these > methods that "everyone" can use. > > Whats the right rails way to achieve this?I''d issue "helper_method :is_editor?" in my application controller. Others prefer a construction like so: class ApplicationHelper def for_editors yield if is_editor? end end Now you can do: <% for_editors do -%> Editors only! <% end -%> Whichever is prettier is a matter of preference I suppose. -- Roderick van Domburg http://www.nedforce.nl -- 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 -~----------~----~----~----~------~----~------~--~---