You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using an ensure block to redirect (see below controller code), this cop raises an error.
I think it's different, but could be related to: #909
defdestroyiflabel_icon.destroyflash[:success]="Label Icon deleted: #{label_icon.name}."endrescueActiveRecord::InvalidForeignKey=>eflash[:error]="Cannot delete #{label_icon.name}, remove from all packing categories first."ensureredirect_toadmin_label_icons_path# <- This action never renders, because of this redirectend
Expected behavior
Rubocop pass
Actual behavior
C: [Correctable] Rails/ActionControllerFlashBeforeRender: Use flash.now before render.
flash[:error] = "Cannot delete #{label_icon.name}, remove from all packing categories first."
^^^^^
There is a similar false positive when using a conditional followed by rescue:
context'when using `flash` before a `redirect_to` in a conditional branch followed by render & rescue'doit'does not register an offense'doexpect_no_offenses(<<~RUBY) class HomeController < ApplicationController def create if condition? flash[:notice] = "success" redirect_to login_path else flash.now[:error] = "conditional error" render :new end rescue ActionController::ParameterMissing flash.now[:form_errors] = "param error" render :new end end RUBYendend
When using an
ensure
block to redirect (see below controller code), this cop raises an error.I think it's different, but could be related to: #909
Expected behavior
Rubocop pass
Actual behavior
Steps to reproduce the problem
Run rubocop on the above code.
RuboCop version
The text was updated successfully, but these errors were encountered: