Silvy@funmail.com
2006-Jan-27 22:39 UTC
[Rails] Trying to understand the difference between similar iterators
What''s the difference between these two?
Objective:
Trying to display the addresses of the students that has "has_many"
relations with addresses
<td><% @student.addresses.each {|address| "Address:
#{address.addr1}<br/>"} %> </td> ****** did not work
<% end %>
This code worked:
<td><% @student.addresses.each do |address|%>
<%= address.addr1 %><br/>
<% end %>
Any comments appreciated.
Thanks
Silvy Mathews
Eric Goodwin
2006-Jan-27 22:45 UTC
[Rails] Trying to understand the difference between similar iterators
Hi,
You shouldn''t need the <% end %> because you are passing in a
block.
This should work as well.
<% @student.addresses.each {|address| %>
<%= address.addr1 %><br/>
<% } %>
Eric
Silvy@funmail.com wrote:> What''s the difference between these two?
> Objective:
> Trying to display the addresses of the students that has
"has_many"
> relations with addresses
>
> <td><% @student.addresses.each {|address| "Address:
> #{address.addr1}<br/>"} %> </td> ****** did not work
> <% end %>
>
> This code worked:
> <td><% @student.addresses.each do |address|%>
> <%= address.addr1 %><br/>
> <% end %>
>
> Any comments appreciated.
> Thanks
> Silvy Mathews
>
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Eric Goodwin
http://www.ericgoodwin.com
Pat Maddox
2006-Jan-27 22:47 UTC
[Rails] Trying to understand the difference between similar iterators
Well first of all, when you''re iterating through a block, you
don''t
need to have an end. In fact it should give you some kind of error.
Secondly, <% just evals a statement, <%= renders the output. So your
loop should be:
<td><%= @student.addresses.each {|address| "Address:
#{address.addr1}<br/>"} %> </td>
Pat
On 1/27/06, Silvy@funmail.com <Silvy@funmail.com>
wrote:> What''s the difference between these two?
> Objective:
> Trying to display the addresses of the students that has
"has_many"
> relations with addresses
>
> <td><% @student.addresses.each {|address| "Address:
> #{address.addr1}<br/>"} %> </td> ****** did not work
> <% end %>
>
> This code worked:
> <td><% @student.addresses.each do |address|%>
> <%= address.addr1 %><br/>
> <% end %>
>
> Any comments appreciated.
> Thanks
> Silvy Mathews
>
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>