Simple question. Currently, for Post model, this is my setup for the default scope
default_scope :order => 'posts.created_at ASC'
How can I augment this to only have those where :draft => false
Also, how can I make a non-default scope to return those where :draft => true?
Thanks!
Don’t use default_scope in this case. Use these regular scopes:
If you really want to use
default_scope(which I don’t recommend as it limits you and makes you have to get around it later), you can do it like this:and to get drafts later:
But again, if you’re using
default_scopeit means that you want it to ALWAYS use those conditions, and by usingunscopedyou’re basically telling ActiveRecord NOT to do something that you explicitly told it to. To me, this is a hack.