Reputation: 8172
I have already built a Rails app which have a model called Product. Currently, I have an attribute named approved
to mark the approval of a product. So when listing the products, every-time I need to use a where command to check whether approved is true or false? So my question is...
all
method and show only approved ones?Upvotes: 0
Views: 112
Reputation: 44370
Create scope
:
class MyModel < ActiveRecord::Base
scope :approved, -> { where(approved: true) }
end
and use it like:
MyModel.approved
Upvotes: 3