Forum: Ruby on Rails ActionMailer view template:

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
James B. (Guest)
on 2009-04-30 22:49
I am attempting to generate a plain text list from an array of arrays.

If I do this:

<% for currency in @rates -%>
  <% if currency[2] == 'USD' -%>
     <%= currency[2] -%> ............... <%= currency[4] %>
  <% end -%>
<% end -%>

Then I see this:

                                                                         =
                                  USD ............... 1.203804
              =

If I do this:

<% for currency in @rates -%>
     <%= currency[2] -%> ............... <%= currency[4] %>
<% end -%>

Then I see this:

     AED ............... 0.327697
     ANG ............... 0.6879
     ARS ............... 0.324296
     AUD ............... 0.869868

How is the if statement causing the difference?
James B. (Guest)
on 2009-04-30 23:13
James B. wrote:

The problem occurs even if the output line is a literal:

<% if true -%>
  <%= "print this" %>
<% end -%>

<% for currency in @rates -%>
  <% if currency[2] == 'USD' -%>
    <%= "print this" %>
  <% end -%>
<% end -%>

gives this:

  print this

                                                                         =
                                 print this
              =
Steve R. (Guest)
on 2009-05-01 00:47
(Received via mailing list)
You are still getting all the indentation from the iterations that are
skipped (i.e., where the currency is not USD).

<% for currency in @rates -%>
   <% next unless currency[2] == 'USD' -%>
   <%= currency[2] %> ............... <%= currency[4] %>
<% end -%>

I'm not sure you need the minus sign on an emitting tag (<%=) to
suppress the linefeed.

Does this help?
James B. (Guest)
on 2009-05-01 00:54
Steve R. wrote:
> You are still getting all the indentation from the iterations that are
> skipped (i.e., where the currency is not USD).
>
> <% for currency in @rates -%>
>    <% next unless currency[2] == 'USD' -%>
>    <%= currency[2] %> ............... <%= currency[4] %>
> <% end -%>
>
> I'm not sure you need the minus sign on an emitting tag (<%=) to
> suppress the linefeed.
>
> Does this help?

Yes.  Now that I know what is going on this works as I wish:

<% for currency in @rates
     usdd = "#{currency[2]} ............... #{currency[4]}" if
        currency[2] == 'USD'
   end -%>

      <%=usdd%>
This topic is locked and can not be replied to.