Created
August 4, 2009 22:29
-
-
Save thoughtbot/162351 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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