Before going for details.
Question 1:-- What's the meaning of scope here (ie named **scope)?**
what's the benefits of using named scope?
Now:-
from Agile Development with Rails book:--
class Order < ActiveRecord::Base
named_scope :last_n_days, lambda { |days| {:conditions =>
['updated < ?' , days] } }
named_scope :checks, :conditions => {:pay_type => :check}
end
Such a named scope would make finding the last week's worth of orders a snap.
orders = Orders.last_n_days(7)
Scopes can also be combined
orders = Orders.checks.last_n_days(7)
why we are using named_scope here. We can do the same using methods. What's special thing we got using named_scope.
named_scope
is used in Rails<3, which is replaced byscope
in Rails >=3. – Sequent