I
I
IvanN7772017-06-06 20:30:38
Ruby on Rails
IvanN777, 2017-06-06 20:30:38

How to get an array from multiple select collections?

users = Users.all(some more conditional)
The user does not have includes comments
In the view I have a search and user.its_a_magic method where Comment.where(user_id: user.id)
I was offered to select all "comments" and form an array user_id => comment in the controller
And write the method find_comment_by_user
User.includes(:comments).select('users.id, comments.*')
So I will get an array of thoughtsal me and it remains to parse it properly, but no.
It output only user

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question