Re: Get current controller name/action name from view

Phlip
2008-05-11T17:39:35Z

> 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!)