Ruby-on-rails – Rails – controller action name to string

functionruby-on-rails

I have a Rails question.

How do I get a controller action's name inside the controller action?

For example, instead of

def create
  logger.info("create")
end

I want to write something like

def create
  logger.info(this_def_name)
end

What is a way to get this_def_name?

Best Answer

Rails 2.X: @controller.action_name

Rails 3.1.X: controller.action_name, action_name

Rails 4.X: action_name