1

I'm trying to do this:

<%= <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]  %>

Thanks for any help.

Dan Grahn
  • 9,044
  • 4
  • 37
  • 74
dcalixto
  • 411
  • 1
  • 9
  • 26
  • possible duplicate of [Disable HTML escaping in erb templates](http://stackoverflow.com/questions/4699497/disable-html-escaping-in-erb-templates) – Dan Grahn Aug 21 '13 at 14:23

2 Answers2

11

You need to use .html_safe to output HTML tags from a ruby string:

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

But you can do the following, more readable:

<% if params[:status].nil? || params[:status] == Order.statuses[1] %>
  <h1>Products Sent</h1>
<% end %>
MrYoshiji
  • 54,334
  • 13
  • 124
  • 117
1

Here alternative is:

<h1>
  <%= 'Products Purchased' if cond1 %>
  <%= 'Products Sent'      if cond2 %>
</h1>

Or, you can use content_tag helper method for any HTML tag:

<%= content_tag(:h1, 'Products Purchased') if cond1 %>
<%= content_tag(:h1, 'Products Sent') if cond2 %>

Where, cond1 and cond2 are "params[:status].nil? || ..." as you specify

(I wonder what happens when both cond1 and cond2 are false, but I think it is out of this topic)

Fumisky Wells
  • 1,150
  • 10
  • 21