Scope basically adds a class method for retrieving and querying objects. A scope basically narrows the database query.You can use multiple scope in single staement.
We are able to call the methods like this:
Article.featured : This will return all the articles which are featured.(featured = true in databse)
Article.published.featured : This will return article whic are both published and featured.
All scope methods will return an ActiveRecord::Relation object which will allow for further methods or other scopes to be called on it.
Passing a parameter in scope:
If you want to apply a particular condition in every query.Say you always want to fetch the active users from database then you can use:
Special feature::Conditional scope :
In case of false condition it would just fire the query without the scope:comments powered by Disqus