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? -- Posted via http://www.ruby-forum.com/.
James Byrne 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 -- Posted via http://www.ruby-forum.com/.
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? On Apr 30, 2009, at 11:49 AM, James Byrne wrote:> > 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? > -- > Posted via http://www.ruby-forum.com/. > > >
Steve Ross 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%> -- Posted via http://www.ruby-forum.com/.