Ruby Rails - Snippets from a project that don't seem so eloquent
Maybe you can convert this:

scope :filter_active_cars, lambda { |options| 
 filter = {}
 filter[:cars] = {:year =&gt; options[:year]} unless options[:year].empty?
 filter[:makes] = {:id =&gt; options[:make]} unless options[:make].empty?
 filter[:models] = {:id =&gt; options[:model]} unless options[:model].empty?

 joins(:car, :model, :make) 
 .where(filter)
 .includes(:car, :model, :make)
 }
}


to this:

scope :filter_active_cars, lambda do |options| 
 with_option(:car, 'cars.year', :year).
 with_option(:make, 'makes.id', :make).
 with_option(:model, 'models.id', :model)
end

scope :with_option, lambda do |assoc, column, option|
  (options[option].present? ?
    joins(assoc).where(column =&gt; options[option]) :
    self).
  includes(assoc)
end


You can reuse the with_option scope in other models