LoginSignup
0

More than 3 years have passed since last update.

【Rails】 flash時にメッセージにリンクを埋め込む

Last updated at Posted at 2019-04-15

flashで通知させるときにどうすれば文字列にリンクを貼るのか悩んだので書きます。

html_safeを使う

html_safeを使えば解決します。

if @user.save
  link = "<a href=#{edit_user_path(:id)}>こちら</a>"
  flash[:success] = "ユーザー登録に成功しました。変更は#{link}でできます。".html_safe
  redirect_to user_path
end

「こちら」がURLになってますね。
html_safeを末尾に記入すれば解決!

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
0