[Ruby] flash message is not displayed in redirect_to

less than 1 minute read

Event

Even if you write as follows, the flash message is not displayed and msg is included in the query parameter.

redirect_to action: :new, alert:'msg'

solution

Describe as follows.

redirect_to({:action => :new} ,{:alert =>'msg'})

Cause

redirect_to is used as follows.

redirect_to(options = {}, response_options = {})

If you write like the beginning, the flash message will be treated as the first argument.

redirect_to action: :new, alert:'msg'
↓
redirect_to({:action => :new, :alert =>'msg'}, {})