Hi, I was wondering if there were anyway to return the controller name in my view. Any help would be appreciated. Thanks! -Mario -- 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 -~----------~----~----~----~------~----~------~--~---
params[:controller] On Jan 31, 2008 5:51 PM, Mario Flores <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > > I was wondering if there were anyway to return the controller name in my > view. Any help would be appreciated. Thanks! > > -Mario > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 Jan 31, 2008, at 8:21 AM, Mario Flores wrote:> I was wondering if there were anyway to return the controller name > in my > view. Any help would be appreciated. Thanks!Views have a pointer to the controller, but I always setup a couple of convenience variables in ApplicationController that additionally follow Rick''s authentication plugins notation (@current_user): before_filter :set_controller_and_action_names def set_controller_and_action_names @current_controller = controller_name @current_action = action_name end -- fxn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Um, why? params[:controller] and params[:action] do exactly this! On Jan 31, 2008 6:52 PM, Xavier Noria <fxn-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> > On Jan 31, 2008, at 8:21 AM, Mario Flores wrote: > > > I was wondering if there were anyway to return the controller name > > in my > > view. Any help would be appreciated. Thanks! > > Views have a pointer to the controller, but I always setup a couple of > convenience variables in ApplicationController that additionally > follow Rick''s authentication plugins notation (@current_user): > > before_filter :set_controller_and_action_names > > def set_controller_and_action_names > @current_controller = controller_name > @current_action = action_name > end > > -- fxn > > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
you can get the controller name by @controller.controller_name On Jan 31, 2:21 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Um, why? > > params[:controller] and params[:action] do exactly this! > > On Jan 31, 2008 6:52 PM, Xavier Noria <f...-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote: > > > > > > > On Jan 31, 2008, at 8:21 AM, Mario Flores wrote: > > > > I was wondering if there were anyway to return the controller name > > > in my > > > view. Any help would be appreciated. Thanks! > > > Views have a pointer to the controller, but I always setup a couple of > > convenience variables in ApplicationController that additionally > > follow Rick''s authentication plugins notation (@current_user): > > > before_filter :set_controller_and_action_names > > > def set_controller_and_action_names > > @current_controller = controller_name > > @current_action = action_name > > end > > > -- fxn > > -- > Ryan Bigghttp://www.frozenplague.net > Feel free to add me to MSN and/or GTalk as this email.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
you can get the controller''s name through @controller.controller_name in view On Jan 31, 12:21 pm, Mario Flores <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > > I was wondering if there were anyway to return the controller name in my > view. Any help would be appreciated. Thanks! > > -Mario > -- > Posted viahttp://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 Jan 31, 2008, at 10:21 AM, Ryan Bigg wrote:> params[:controller] and params[:action] do exactly this!If you want to ask for the current controller name in a view the right path in my opinion is to, ahem, ask the current controller for its name: <%= controller.controller_name %> That''s proper use of encapsulation. I just happen to prefer an instance variable. -- fxn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
These actually deliver slightly different results. My controller is one of a subest of controllers in an admin directory. admin/products_controller.rb params[:controller] returns "admin/products" controller.controller_name return "products" One may work better than the other, but it really depends on your need. Thanks for the help! -Mario -- 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 -~----------~----~----~----~------~----~------~--~---