我有'like' action在 communties_controller .rb
如果我想获取当前喜欢社区的所有用户,我怎么写控制器呢?我使用的gem名为acts_as_votable
应该是这样的?
@community = Community.find(params[:id])
@users =用户。喜欢@community
communities_controller.rb
def like
if current_user.voted_up_on? @community
current_user.dislikes @community
flash[:notice] = "Deleted from favorite"
else
current_user.likes @community
flash[:notice] = "Added to favorite"
end
respond_to do |format|
format.html { redirect_to @community }
end
end
要获得所有喜欢社区的用户,您可以写
@community.likes
查看acts_as_votable文档,了解您所做的所有其他操作