Skip to content

Instantly share code, notes, and snippets.

@thoughtbot
Created August 4, 2009 22:29
Show Gist options
  • Save thoughtbot/162351 to your computer and use it in GitHub Desktop.
Save thoughtbot/162351 to your computer and use it in GitHub Desktop.
class HouseSearch
attr_accessor :keyword, :price
def initialize(params)
params ||= {}
params.each do |key, value|
self.send("#{key}=", value)
end
end
def id
nil
end
def new_record?
true
end
def results
results = House.all
results = results.within_price_range(self.price) unless self.price.blank?
results
end
def errors
@errors ||= ActiveRecord::Errors.new(self)
@errors.add(:price, "must be a price range") unless self.price =~ /-/
@errors
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment