On Fri, Sep 4, 2015 at 3:26 PM, Rob Biedenharn <r...@agileconsultingllc.com>
wrote:

> On 2015-Sep-4, at 15:56 , Николай Спелый <peavey515...@gmail.com> wrote:
>
> Great !
> I already try write this logic but it not works. But when i copy-paste
> your variant it's work.
> So difference is in formating code, i write in one line, you write in
> three lines.
> That's nice for resolving problem, but why it's works in divided style of
> ruby and not works in one-line style ?
> My one-line is <%= Chat.find_by(id: 6).chatusers.each { |chat_user|
> chat_user.user } %> which about i told.
>
>
The problem is that ruby is swallowing whatever happens inside the .each --
what you want is probably .map instead. The return value from .each is the
collection. The return value from map is a new collection of the results of
the block.

Try this:

    Chat.find_by(id: 6).chatusers.map{|chat_user| chat_user.user}

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAHUC_t9j5P%2Bdop3hN6%2BujS7EoTyHqnHtuO__qT117swga8SaVw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to