Last Updated: March 21, 2019
· cesc1989

Get the controller name and action name in a view

I'd normally do the following to know the controller and action in a defined view:

<%= params[:controller] %>
<%= params[:action] %>

Just today, found out there are two other (easier) ways to get those values:

<%= controller_name %>
<%= action_name %>

See docs for controller_name