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


Tony McKeown
Tony McKeown
Courses Plus Student 14,300 Points

acts_as_votable gem - Help!

I've been using the acts_as_votable gem but I've ran into a problem trying to extract information from it.

At the moment I have a user profile page which you can press a button to like that user. This is basically to say that you like this band.

I have another model called events. Each event has a performer which stores the bands profile name. On the index page of events, I'd like to to show all the events which feature the bands that you like.

The problem is that I can't quite extract the information in the right way to compare the profile_name of a user you like and the profile_name of the performer of an event.

current_user.get_up_voted(User) would get me a list of the users you have liked but how would I then compare their profile names with the performer field of an event?

If I did the following I could loop through the profile_names of the bands liked by the current user.

<% current_user.get_up_voted(User).each do |user| %>
<%= user.profile_name %>
<% end %>

So thought I could construct a method in the controller like this

def users_liked_by_you
        current_user.get_up_voted(User).each do |user|

And then run

@event_favourites = Event.where("performer = ?", @users_liked_by_you)

But it is blank on the index page. Am I anywhere near getting it right?

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

For starters, your method users_liked_by_you does not seem to do anything with the names. It just iterates through them, gets each profile_name and then does nothing else, goes to the next one. It does not return anything at the end either, so it will just result in a blank page.