【问题标题】:A Voter and Votable User model with acts_as_votable plugin?带有acts_as_votable插件的投票者和投票用户模型?
【发布时间】:2012-08-20 12:51:58
【问题描述】:

我正在为 Ruby on Rails 使用acts_as_votable 插件。我的应用程序中只有一个 User 模型,并决定不创建 Profile 模型,因为字段有限。有没有办法让用户既可以投票又可以投票?我的用户应该能够创建他们的个人资料,对除了他们自己的个人资料之外的其他个人资料进行投票。

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    乍一看,你应该可以做到

    class User << ActiveRecord::Base
      acts_as_votable
      acts_as_voter
    
      # ...
    end
    

    然后做

    user1 = User.find(some_id)
    user2 = User.find(some_other_id)
    
    user1.liked_by user2
    

    【讨论】:

      猜你喜欢
      • 2014-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-14
      • 2013-10-24
      • 2019-04-03
      相关资源
      最近更新 更多