I am using the thumbsup gem to allow users to vote on microposts and now I am trying to render all of the users that have voted for a select micropost. All of the voting functionality and routes work fine, however I am now getting the error from my Micropost controller:
undefined method `voted_for?'
micropost controller:
def into_it #for the view; displays who likes the post
@micropost = Micropost.find(params[:id])
@users = User.voted_for?(@micropost)
render 'show_users_into_it'
end
micropost model:
acts_as_voteable
User model:
acts_as_voter
Schema info:
# Table name: users
# id
# name
# email
# Table name: microposts
# id :integer
# comment :text
# user_id :integer
# Table name: votes
# id :integer not null, primary key
# vote :boolean default(FALSE), not null
# voteable_id :integer not null
# voteable_type :string(255) not null
# voter_id :integer
# voter_type :string(255)
Do I have to do some sort of SQL query instead is there no simple way? thanks.
You are getting an undefined method
voted_for?because you are calling it on the User class instead of an instance of the user.I think the method you’re looking for is voters_who_voted which would be used like: