Why doesn't it print out username?

Hi all

I have the following code in an rhtml template:

<%= member.buddies_not_confirmed.each { |b| b.username } %>

I want it to print out

PeterPaulMary etc.

But it prints me

#Member:0x24a7e0c#Member:0x24a7dd0#Member:0x24a7d80 etc.

What’s wrong here? Sorry for this newbie-like question (although I am a
newbie :wink: ).

Thanks for help.
Josh

Joshua M. wrote:

But it prints me

#Member:0x24a7e0c#Member:0x24a7dd0#Member:0x24a7d80 etc.

What’s wrong here? Sorry for this newbie-like question (although I am a
newbie :wink: ).

The .each method actually returns the original array, not the result of
the block applied to each member. You either want to do:

<% for buddy in member.buddies_not_confirmed -%>
<%= buddy.username %>
<% end -%>

or possibly:

<%= member.buddies_not_confirmed.collect{|b| b.username}.join %>

Easy mistake to make :slight_smile:

<%= member.buddies_not_confirmed.collect{|b| b.username}.join %>

Easy mistake to make :slight_smile:

OK, thanks a lot. :slight_smile: