Rails在erb标签中嵌入了html标签?

时间:2013-08-21 14:21:22

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1

我正在尝试这样做:

<%= <h1>Products Purchased </h1> if  params[:status].nil? || params[:status] == Order.statuses[0]  %>

<%= "<h1>Products Sent </h1>" if  params[:status].nil? || params[:status] == Order.statuses[1]  %>

感谢您的帮助。

1 个答案:

答案 0 :(得分:6)

您需要使用.html_safe从ruby字符串输出HTML标记:

<%= "<h1>Products Sent </h1>".html_safe if params[:status].nil? || params[:status] == Order.statuses[1]  %>

但你可以做到以下,更具可读性:

<% if params[:status].nil? || params[:status] == Order.statuses[1] %>
  <h1>Products Sent</h1>
<% end %>