instance method method_for_action

Ruby on Rails 6.1.7.10

Since v3.0.20 Private — implementation detail, not part of the public API

Available in: v3.0.20 v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

method_for_action(action_name)

Takes an action name and returns the name of the method that will handle the action. In normal cases, this method returns the same name as it receives. By default, if #method_for_action receives a name that is not an action, it will look for an #action_missing method and return “_handle_action_missing” if one is found.

Subclasses may override this method to add additional conditions that should be considered an action. For instance, an HTTP controller with a template matching the action name is considered to exist.

If you override this method to handle additional cases, you may also provide a method (like _handle_method_missing) to handle the case.

If none of these conditions are true, and method_for_action returns nil, an AbstractController::ActionNotFound exception will be raised.

Parameters
  • action_name - An action name to find a method name for

Returns
  • string - The name of the method that handles the action

  • nil - No method name could be found.

Parameters

action_name req
Source
# File actionpack/lib/abstract_controller/base.rb, line 286
      def method_for_action(action_name)
        if action_method?(action_name)
          action_name
        elsif respond_to?(:action_missing, true)
          "_handle_action_missing"
        end
      end

Defined in actionpack/lib/abstract_controller/base.rb line 286 · View on GitHub · Improve this page · Find usages on GitHub

Defined in AbstractController::Base

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close