2
class Idea < ActiveRecord::Base
attr_accessible :archived, :checked, :content, :note, :stared
scope :stared, -> { where(stared: true)
end
使用此代碼,我如何測試範圍(如stared
)是否在Idea
上定義。我想要這個效果如何檢查模型是否定義了範圍?
Idea.has_scope?(:stared)
=> true
Idea.has_scope?(:unknown)
=> false
它將測試比對其他領域的所有實例方法。 – steveyang