Hi Chaps, How can I check if the page is using a controllers action. for example i got a helper method that needs to know if a certain controller action is run on the page or not so as to display different content for it. Thought it was just code = "xyz" if Controllername.action? Cheers, Rog -- 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 Feb 18, 1:38 pm, Roger Muthton <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi Chaps, > > How can I check if the page is using a controllers action. for example i > got a helper method that needs to know if a certain controller action is > run on the page or not so as to display different content for it. > > Thought it was just > > code = "xyz" if Controllername.action? > > Cheers, > > Rog > -- > Posted viahttp://www.ruby-forum.com/.If I correctly understood what you need, you may try using:> Controller.action_methods.include?params[:action]Where params[:action] will contain the slice of the url corresponding to the action in the last request --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Roger, On Wed, 2009-02-18 at 13:38 +0100, Roger Muthton wrote:> Hi Chaps, > > How can I check if the page is using a controllers action. for example i > got a helper method that needs to know if a certain controller action is > run on the page or not so as to display different content for it. > > Thought it was just > > code = "xyz" if Controllername.action?Your views have access to the controller and method that rendered them via controller.controller_name and controller.action_name e.g., <% if controller.controller_name == ''posts'' %> <% if controller.action_name == ''create'' %> <%= do whatever %> <% end %> <% end %> HTH, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---