Given:
@votes (user_id, option_id)
If do: @project.votes I get all the votes for that project.
If I then want to see what the current user voted for I have to do:
Votes.where(:user_id => current_user.id).first
This is a record that’s already in the @project votes query. Is there a way I can find the record in that first query w/o having to rehit the db?
Thanks
You can just use the regular ruby Enumerable#select method:
This will return an array of all the user’s votes for the project. If the user is only allowed one vote, and you want a single value, not an array, just use
.firstlike so: