Conditionally use `helper_method` in Flash concern

I was attempting to use the `flash` functionality in a `Metal`
controller. When including the `flash` concern I received the following
error:

    NoMethodError: undefined method `helper_method'....

Either:

- `AbstractController::Helpers` should be a dependency of
  `ActionController::Flash`
- `ActionController::Flash` should not require the existence of
  `AbstractController::Helpers`.

Since my use case (set a flash and redirect) has no need for the helper
method and that is a common use case, making the dependency conditional
seemed the better option.

NOTE: This is similar to issue #21067 only the error is within Rails
itself while that issue had the error within Devise.
上级 3000c149
......@@ -33,10 +33,12 @@ def add_flash_types(*types)
types.each do |type|
next if _flash_types.include?(type)
define_method(type) do
request.flash[type]
if respond_to? :helper_method
define_method(type) do
request.flash[type]
end
helper_method type
end
helper_method type
self._flash_types += [type]
end
......
......@@ -342,6 +342,14 @@ def test_flash_factored_into_etag
end
end
def test_flash_usable_in_metal_without_helper
assert_nothing_raised do
Class.new ActionController::Metal do
include ActionController::Flash
end
end
end
private
# Overwrite get to send SessionSecret in env hash
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册