I have a scenario where I would like to have the name of the view that will be rendering while I\'m in the layout file. I can find solutions to find which layout will be wra
I like the following approach, as you can reduce code size a good bit in a lot of cases. Include this in your application_controller.rb:
before_filter :instantiate_controller_and_action_names
caches_action :instantiate_controller_and_action_names
def instantiate_controller_and_action_names
@current_action = action_name
@current_controller = controller_name
end
Then, if your views correspond to an action, you just do:
dosomething if @current_action == 'new'