RailsでJavaScriptでの遷移時にフラッシュを表示させる
調べるとフラッシュに相当する文言を隠して( display: none
とか?) おいて、JavaScriptで表示させる( display: block
とか)の方法しかなかった。GETパラメータで送るのヤダなぁと思ったので別の方法を考えた。
アクションを作ってフラッシュ付きでリダイレクトさせる
具体的にはこう。
location.href = '/items/redirect_with_flash_message';
class ItemsController < WebController def redirect_with_flash_message flash[:alert] = 'ログインが必要です' redirect_to new_user_session_path end end