Re: Get current controller name/action name from view

michael_teter
2008-05-11T18:27:26Z

Excellent, thanks!

I also just found this:
http://snippets.dzone.com/posts/show/4391

<%= controller.controller_name %>
<%= controller.action_name %>

On May 11, 12:39 pm, Phlip
<phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> > In a view I would like to get the current controller name and action
> > that was used to get here.
>
> params[:controller]
> params[:action]
>
> > In this template I''m constructing some links to specific
parameter
> > calls of this same template, and I need to know which controller was
> > used and what action was called to get us here.  I thought it was
> > something like this:
>
> > link_to "This Year", :controller => @controller.name,
:action =>
> > @controller.action
>
> Use url_for (or a named route), then _don''t_ pass the controller
in. Url_for
> will find the controller in params if you don''t pass it in.
>
> (Write tests for all this stuff, using assert_xpath, to detect you are
getting
> the links you expect!)