【问题标题】:Scope for acts_as_commentableact_as_commentable 的范围
【发布时间】:2014-04-04 00:38:46
【问题描述】:

有谁知道检查用户是否对模型发表评论的范围?例如,像这样:

current_member.commented_on?

如果没有,有没有办法创建一个?

【问题讨论】:

    标签: ruby-on-rails filter scope acts-as-commentable


    【解决方案1】:

    据我所知。有两种可能的方法来做到这一点

    1.第一种方法

    class Post < ActiveRecord::Base
      def self.commented_on
        Your selection query like where("query what you want to do e.g current_member.posts")
        and you can also return values
      end
    end
    

    2.第二种方法

    second method
    class Post < ActiveRecord::Base
      scope :commented_on, -> { where("your query here") }
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-06
      • 1970-01-01
      • 2022-11-12
      相关资源
      最近更新 更多