Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RailsでJavaScriptでの遷移時にフラッシュを表示させる

Last updated at Posted at 2020-02-16

やりたいこと

RailsでJavaScriptで遷移させるときに、フラッシュを表示させたい。
調べるとフラッシュに相当する文言を隠して( display: none とか?) おいて、JavaScriptで表示させる( display: block とか)の方法しかなかった。
GETパラメータで送るのヤダなぁと思ったので別の方法を考えた。

やったこと

アクションを作ってフラッシュ付きでリダイレクトさせる

具体的にはこう。

items.js
location.href = '/items/redirect_with_flash_message';
items_controller.rb
class ItemsController < WebController
  def redirect_with_flash_message
    flash[:alert] = 'ログインが必要です'

    redirect_to new_user_session_path
  end
end

どうでもいいけどRailsのタグ、スペル間違ってない?

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Comments

No comments

Let's comment your feelings that are more than good

Qiita Advent Calendar is held!

Qiita Advent Calendar is an article posting event where you post articles by filling a calendar 🎅

Some calendars come with gifts and some gifts are drawn from all calendars 👀

Please tie the article to your calendar and let's enjoy Christmas together!

0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Login to continue?

Login or Sign up with social account

Login or Sign up with your email address