在使用acts_as_votable时,如何获取所有喜欢社区的用户?

时间:2013-01-05 00:53:07

标签: ruby-on-rails ruby-on-rails-3

我在 communities_controller.rb 中有'喜欢'操作 如果我想获取当前喜欢社区的所有用户该怎么办?如何在控制器中编写? 我正在使用名为 acts_as_votable

的gem

应该是这样的吗?

  

@community = Community.find(params [:id])
  @users = User.likes @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

1 个答案:

答案 0 :(得分:1)

要让所有喜欢社区的用户都可以写

@community.likes

查看acts_as_votable Documentation以了解您执行的所有其他操作。