-
-
Notifications
You must be signed in to change notification settings - Fork 282
Open
Labels
bugSomething isn't workingSomething isn't working
Description
When flash
is called inside a block, a violation of Rails/ActionControllerFlashBeforeRender
is thrown even when the action calls redirect_to
.
Expected behavior
A violation should not occur when a redirect is being performed
Actual behavior
Even in a clean action (i.e. no control flow where sometimes it renders and sometimes it redirects), a violation is raised.
Steps to reproduce the problem
This action is reported as violating the rule:
def test
messages = %w[a b c d]
messages.each { flash[:error] = _1 }
redirect_to(some_path)
end
The same problem occurs when called in a multi-line block:
def test
messages = %w[a b c d]
messages.each do |message|
flash[:error] = message
end
redirect_to(some_path)
end
The issue does not occur if you assign the array directly to flash:
def test
messages = %w[a b c d]
flash[:error] = messages
redirect_to(some_path)
end
RuboCop version
1.56.4 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 3.2.2) [arm64-darwin23]
- rubocop-factory_bot 2.24.0
- rubocop-i18n 1.14.1
- rubocop-performance 1.19.1
- rubocop-rails 2.22.1
- rubocop-rspec 2.24.1
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working