Can I get the name of the current controller in the view ?
Can I get the name of the current controller in the view ?
There is a solution for controller in view:
Controller_name holds the name of the controller used to serve current view.
Note: The :controller and :action keys use the methods controller_name and action_name instead to access values.
CSS active class link full page is currently open that can different style.static_pages controller with an about action,
<li> <a class='button <% if controller.controller_name == "static_pages" && controller.action_name == "about" %>active<%end%>' href="/about"> About Us </a> </li>
Here alternatively try by using this below command:
#to get controller name: <%= controller.controller_name %> #=> 'users' #to get action name, it is the method: <%= controller.action_name %> #=> 'show' #to get id information: <%= ActionController::Routing::Routes.recognize_path(request.url)[:id] %> #=> '23' # or display nicely <%= debug Rails.application.routes.recognize_path(request.url) %>