ruby 使用范围为模型定义类方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 使用范围为模型定义类方法相关的知识,希望对你有一定的参考价值。

class Shirt < ActiveRecord::Base
  scope :red -> { where('color = ?', 'red') }
  scope :dry_clean_only, -> { joins(:washing_instructions).where('washing_instructions.dry_clean_only = ?', true) }
end

# The methods can then be accessed as such
Shirt.red
Shirt.dry_clean_only

以上是关于ruby 使用范围为模型定义类方法的主要内容,如果未能解决你的问题,请参考以下文章