Using lambda with named scopes in Rails 3

You can define an ActiveRelation named scope inside your model Address, for example, like so:

class Address < ActiveRecord::Base
  scope :search, lambda {|query| where(["name LIKE ?", "%#{query}%"])}
end
VN:F [1.9.22_1171]
Rating: 3.8/5 (6 votes cast)
VN:F [1.9.22_1171]
Rating: +3 (from 5 votes)
Using lambda with named scopes in Rails 3, 3.8 out of 5 based on 6 ratings
Facebook Twitter Email

2 Comments to “Using lambda with named scopes in Rails 3”