Put a link in a flash[:notice]

后端 未结 8 1486
天涯浪人
天涯浪人 2020-12-04 23:31

I am learning Ruby and Rails.

I have a Ruby on Rails project that tracks jobs a server is running. Right now, when I manually create a new job, it announces:

<
8条回答
  •  粉色の甜心
    2020-12-05 00:11

    The selected answer didn't work for me. But the answer from this post worked. I'm using Rails 4.2.4 by the way. With guidance from the answer I linked, here's how I did it:

    View

    <% flash.each do |name, msg| %>
      
    <%= sanitize(msg) %>
    <% end %>

    Controller

    flash[:success] = "Blah blah. #{view_context.link_to('Click this link', '/url/here')}"
    

    The magic is the sanitize method.

    I didn't need to use .html_safe as well.

提交回复
热议问题