Hi, I was wondering if there were anyway to return the controller name in my view. Any help would be appreciated. Thanks! -Mario
on 2008-01-31 08:21
on 2008-01-31 08:45
params[:controller] On Jan 31, 2008 5:51 PM, Mario Flores <rails-mailing-list@andreas-s.net> wrote: > > > -- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email.
on 2008-01-31 09:23
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
on 2008-01-31 10:23
Um, why? params[:controller] and params[:action] do exactly this! On Jan 31, 2008 6:52 PM, Xavier Noria <fxn@hashref.com> wrote: > > > > -- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email.
on 2008-01-31 10:41
you can get the controller's name through @controller.controller_name in view On Jan 31, 12:21 pm, Mario Flores <rails-mailing-l...@andreas-s.net>
on 2008-01-31 10:56
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
on 2008-01-31 18:12
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
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.