RE: Trying to understand the difference between similaritera

No I have tried that. It gives me just this output #

[email protected] wrote:

No I have tried that. It gives me just this output #

That’s because the <%= %> construct outputs the return value of the
expression inside it. The .each method actually returns the object it’s
called on - which in this case would be @student.addresses, which isn’t
a string… Try:

<%= @student.addresses.inject{|s, address| s + "Address: #{address.addr1}
"} %>

Alex Y. wrote:

[email protected] wrote:

No I have tried that. It gives me just this output #
That’s because the <%= %> construct outputs the return value of the
expression inside it. The .each method actually returns the object it’s
called on - which in this case would be @student.addresses, which isn’t
a string… Try:

<%= @student.addresses.inject{|s, address| s + "Address: #{address.addr1}
"} %>

Oops… That should probably be

<%= @student.addresses.inject(''){|s, address| s + "Address: #{address.addr1}
"} %>