Rails - controller action name to string

Pavel K. picture Pavel K. · Aug 7, 2009 · Viewed 106.1k times · Source

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?

Answer

JellicleCat picture JellicleCat · Nov 25, 2010

Rails 2.X: @controller.action_name

Rails 3.1.X: controller.action_name, action_name

Rails 4.X: action_name