mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make action_method? public and change implicit rendering to override it instead.
This commit is contained in:
parent
58becf1165
commit
ba51aa0b1b
3 changed files with 25 additions and 19 deletions
|
@ -128,20 +128,23 @@ module AbstractController
|
|||
self.class.action_methods
|
||||
end
|
||||
|
||||
private
|
||||
# Returns true if the name can be considered an action. This can
|
||||
# be overridden in subclasses to modify the semantics of what
|
||||
# can be considered an action.
|
||||
#
|
||||
# For instance, this is overriden by ActionController to add
|
||||
# the implicit rendering feature.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * <tt>name</tt> - The name of an action to be tested
|
||||
#
|
||||
# ==== Returns
|
||||
# * <tt>TrueClass</tt>, <tt>FalseClass</tt>
|
||||
def action_method?(name)
|
||||
self.class.action_methods.include?(name)
|
||||
end
|
||||
|
||||
# Returns true if the name can be considered an action. This can
|
||||
# be overridden in subclasses to modify the semantics of what
|
||||
# can be considered an action.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * <tt>name</tt> - The name of an action to be tested
|
||||
#
|
||||
# ==== Returns
|
||||
# * <tt>TrueClass</tt>, <tt>FalseClass</tt>
|
||||
def action_method?(name)
|
||||
self.class.action_methods.include?(name)
|
||||
end
|
||||
private
|
||||
|
||||
# Call the action. Override this in a subclass to modify the
|
||||
# behavior around processing an action. This, and not #process,
|
||||
|
@ -160,8 +163,8 @@ module AbstractController
|
|||
# If the action name was not found, but a method called "action_missing"
|
||||
# was found, #method_for_action will return "_handle_action_missing".
|
||||
# This method calls #action_missing with the current action name.
|
||||
def _handle_action_missing
|
||||
action_missing(@_action_name)
|
||||
def _handle_action_missing(*args)
|
||||
action_missing(@_action_name, *args)
|
||||
end
|
||||
|
||||
# Takes an action name and returns the name of the method that will
|
||||
|
|
|
@ -14,10 +14,8 @@ module ActionController
|
|||
render
|
||||
end
|
||||
|
||||
def method_for_action(action_name)
|
||||
super || if template_exists?(action_name.to_s, _prefixes)
|
||||
action_name.to_s
|
||||
end
|
||||
def action_method?(action_name)
|
||||
super || template_exists?(action_name.to_s, _prefixes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,5 +24,10 @@ module RenderImplicitAction
|
|||
assert_body "Hello hyphen-ated!"
|
||||
assert_status 200
|
||||
end
|
||||
|
||||
test "action_method? returns true for implicit actions" do
|
||||
assert SimpleController.new.action_method?(:hello_world)
|
||||
assert SimpleController.new.action_method?(:"hyphen-ated")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue