How to get request's target controller and action with Rails 3?
In the application controller before filter.
class ApplicationController < ActionController::Base
before_filter :authenticate
def authenticate
# How do we know which controller and action was targetted?
end
end
Solution 1:
class ApplicationController < ActionController::Base
before_filter :authenticate
def authenticate
# How do we know which controller and action was targetted?
params[:controller]
params[:action]
# OR
controller.controller_name
controller.action_name
end
end
Solution 2:
In Rails 3.2 you no longer need to call controller.action_name explicitly instead just "action_name".
before_filter :check_if_locked
def check_if_locked
puts action_name
puts controller_name
end