Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Collecting and Displaying all Users who have liked your specific items

Hey guys,

I was able to set up on my Rails app a way to get all Users who have liked all the items on the Rails app.

But, what I would like to do is only get the Users who have liked my specific items on the Rails app. I have listed below the relevant code. I have also included my github here in case it help https://github.com/OmarZV/sort2

Index.html.erb

<%- @likers.each do |liker| %> <%= image_tag liker.avatar, width: 25, class: "css-style" %>&nbsp<%= liker.username %> <% end %>

Items_controller

def index
@items = Item.order("created_at DESC") if current_user.present? @likers = Item.where("user_id", current_user.id).map(&:users).flatten end
end