Ruby on rails 使用或链接多个作用域

Ruby on rails 使用或链接多个作用域,ruby-on-rails,activerecord,Ruby On Rails,Activerecord,我有上面的望远镜 我想这样做:@example=example.target\u self.target\u other 但是,我希望它同时返回target“self”和target“other”(很抱歉,这让人困惑,我想查询以使用,或者,尽管我希望所有记录都有这两个标记) 现在,它不会返回任何内容,因为没有任何内容同时标记了self和other 谢谢 您可以在何处编写(目标:['self','other']),或者添加如下范围: scope :target_self, -> { wh

我有上面的望远镜

我想这样做:
@example=example.target\u self.target\u other

但是,我希望它同时返回target“self”和target“other”(很抱歉,这让人困惑,我想查询以使用,或者,尽管我希望所有记录都有这两个标记)

现在,它不会返回任何内容,因为没有任何内容同时标记了self和other


谢谢

您可以在何处编写
(目标:['self','other'])
,或者添加如下范围:

  scope :target_self, -> { where(target: 'self') }
  scope :target_other, -> { where(target: 'other') }
然后像
Example那样调用它

scope :with_targets, -> (targets) { where(target: targets) }