我需要在 Flash 通知中添加换行符。到目前为止我有这个
flash[:success] = "We will notify you when we go LIVE! #{<br />} Meantime, complete this quick survey so we can get to know your interest.
Run Code Online (Sandbox Code Playgroud)
但这是不正确的。有谁知道如何在控制器中正确执行此操作?
我正在使用 ruby 2.2.1p85 和 Rails 4.0.10
在编程中总是有一种肮脏的方式来做事。在这里您可以在闪存内创建多行阵列。
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."
Run Code Online (Sandbox Code Playgroud)
并像这样显示它
<% flash.each do |key, value| %>
<% value.each do |text| %>
<%= content_tag :div, text %>
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
这肯定会起作用。
但最好的方法是这样做
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
Run Code Online (Sandbox Code Playgroud)
如果这也不起作用,请尝试其他方法
在控制器组中
flash[:success] = "We will notify you when we go LIVE! <br> Meantime, complete this quick survey so we can get to know your interest."
Run Code Online (Sandbox Code Playgroud)
并在视图中显示类似
<% flash.each do | value| %>
<%= content_tag :div, value.html_safe %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3537 次 |
| 最近记录: |