ERB Template removing the trailing line

Posted by KandadaBoggu on Stack Overflow See other posts from Stack Overflow or by KandadaBoggu
Published on 2011-01-08T07:20:48Z Indexed on 2011/01/08 7:53 UTC
Read the original article Hit count: 246

Filed under:
|

I have an ERB template for sending an email.

Name: <%= @user.name %>
<% unless @user.phone.blank? %>
Phone: <%= @user.phone %>
<% end %>
Address: <%= @user.address %>

When the user hasn't set the phone then the email body is as follows:

Name: John Miller 

Address: X124 Dummy Lane, Dummy City, CA

I am trying to remove the blank line between Name and Address when Phone is empty.

Name: John Miller 
Address: X124 Dummy Lane, Dummy City, CA

I have tried to use <%--%> tags(to remove the trailing new line) without any success.

Name: <%= @user.name %>
<%- unless @user.phone.blank? -%>
Phone: <%= @user.phone %>
<%- end -%>
Address: <%= @user.address -%>

How do I work around this issue?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about erb