class Photo < ActiveRecord::Base scope :filter, lambda { |filter| where('LOWER(name) LIKE :filter', :filter => "%#{filter.present? ? filter.downcase : ''}%") } attr_accessible :name end