Before proceeding to the details.
Question 1: - What is the scope here (i.e. named ** scope )? **
What are the benefits of using a named scope?
Now: -
from Agile Development's book with Rails: -
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 area will allow us to find the value of snap orders last week.
orders = Orders.last_n_days(7)
Areas can also be combined.
orders = Orders.checks.last_n_days(7)
why we use named_scope here. We can do the same with methods. What special thing we got with named_scope.
ruby-on-rails
Mohit Jain May 27 '10 at 9:00 a.m. 2010-05-27 09:00
source share