Roseanne Zhang
2006-Oct-13 14:57 UTC
How to get current method/action name from layout rhtml
I want to know what is current controller / action in my layout.rhtml shared by all my rhtml files to make some style changes. I am new in ruby and RoR, I believe there must be a simple solution for this. Any help would be great appreciated!!! Roseanne -- 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 -~----------~----~----~----~------~----~------~--~---
Thorsten L
2006-Oct-13 15:14 UTC
Re: How to get current method/action name from layout rhtml
There sure is a better soluition, but i added a before_filter in my application controller like this: before_filter :set_canames ... private def set_canames @cname = controller_name @aname = action_name end there probably is a better way, but it works. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Brandt Lofton
2006-Oct-13 15:20 UTC
Re: How to get current method/action name from layout rhtml
In your views, you can use controller.controller_name and I''m sure there is a method for the action but I don''t know it off the top of my head. action_name would make the most sense. On 10/13/06, Thorsten L <duplexxx-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > > There sure is a better soluition, but i added a before_filter in my > application controller like this: > > before_filter :set_canames > > ... > private > def set_canames > @cname = controller_name > @aname = action_name > end > > there probably is a better way, but it works. > > > > >-- -B --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thorsten L wrote:> > There sure is a better soluition, but i added a before_filter in my > application controller like this: > > before_filter :set_canames > > ... > private > def set_canames > @cname = controller_name > @aname = action_name > end > > there probably is a better way, but it works. >There was a recent post with similar information. I believe you do have access to ''controller'' in the views (and layouts) therefore it is possible to use controller.controller_name controller.action_name Long --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Roseanne Zhang
2006-Oct-13 15:46 UTC
Re: How to get current method/action name from layout rhtml
Long wrote:> Thorsten L wrote:> > controller.controller_name > controller.action_name > > LongThanks everybody!!! Thanks Long!!! It works great! Roseanne -- 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 -~----------~----~----~----~------~----~------~--~---