我需要在闪存通知中添加换行符。到目前为止我有这个
flash[:success] = "We will notify you when we go LIVE! #{<br />} Meantime, complete this quick survey so we can get to know your interest.
但这是不正确的。有谁知道如何在控制器中正确执行此操作?
我正在使用ruby 2.2.1p85&amp; Rails 4.0.10
答案 0 :(得分:4)
在编程中总是有一种肮脏的方法。在这里你可以在flash中创建多线阵列。
flash[:success] = []
flash[:success] = flash[:success] << "We will notify you when we go LIVE! "
flash[:success] = flash[:success] << "Meantime, complete this quick survey so we can get to know your interest."
并像这样显示
<% flash.each do |key, value| %>
<% value.each do |text| %>
<%= content_tag :div, text %>
<% end %>
<% end %>
这肯定会奏效。
但最好的办法就是这个
flash[:success] = "We will notify you when we go LIVE! <br> Meantime, complete this quick survey so we can get to know your interest.".html_safe
如果这也不起作用,那就试试另一种方式
在控制器集
中flash[:success] = "We will notify you when we go LIVE! <br> Meantime, complete this quick survey so we can get to know your interest."
并在视图中显示
<% flash.each do | value| %>
<%= content_tag :div, value.html_safe %>
<% end %>
答案 1 :(得分:1)
flash[:success] = "We will notify you when we go LIVE! <br> Meantime, complete this quick survey so we can get to know your interest."
redirect_to YOUR_URL, flash: { html_safe: true }
答案 2 :(得分:0)
添加<br/>
标记而不进行插值,它将起作用。
"We will notify you when we go LIVE! <br/> Meantime, complete this quick survey so we can get to know your interest."