Ruby on rails 显示投票支持帖子的用户竖起大拇指
我正在使用拇指支持gem来允许用户在micropost上投票,现在我正在尝试呈现所有投票给selectmicropost的用户。所有的投票功能和路线都可以正常工作,但是我现在从我的Micropost控制器得到了错误:Ruby on rails 显示投票支持帖子的用户竖起大拇指,ruby-on-rails,controller,gem,undefined,Ruby On Rails,Controller,Gem,Undefined,我正在使用拇指支持gem来允许用户在micropost上投票,现在我正在尝试呈现所有投票给selectmicropost的用户。所有的投票功能和路线都可以正常工作,但是我现在从我的Micropost控制器得到了错误: undefined method `voted_for?' def into_it #for the view; displays who likes the post @micropost = Micropost.find(params[:id]) @users =
undefined method `voted_for?'
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控制器:
undefined method `voted_for?'
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
微观模型:
acts_as_voteable
用户模型:
acts_as_voter
架构信息:
# 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)
我需要做一些SQL查询吗?没有简单的方法吗?谢谢。这是因为@users=User.voated_for?(@micropost)将返回true或false,但不会返回实例对象。尝试查看此链接这是因为@users=User.voated_for?(@micropost)将返回true或false,但不会返回实例对象。尝试查看此链接您将获得一个未定义的方法投票支持?,因为您在用户类而不是用户实例上调用它 我认为您正在寻找的方法是:
def into_it #for the view; displays who likes the post
@micropost = Micropost.find(params[:id])
@users = @micropost.voters_who_voted
render 'show_users_into_it'
end
您得到了一个未定义的方法
投票支持?
,因为您是在用户类而不是用户实例上调用它
我认为您正在寻找的方法是:
def into_it #for the view; displays who likes the post
@micropost = Micropost.find(params[:id])
@users = @micropost.voters_who_voted
render 'show_users_into_it'
end
谢谢,我对编程概念很陌生,这很有意义。谢谢,我对编程概念很陌生,这很有意义。干杯