Skip to content

Instantly share code, notes, and snippets.

@theotherzach
Created June 20, 2013 21:10
Show Gist options
  • Select an option

  • Save theotherzach/5826681 to your computer and use it in GitHub Desktop.

Select an option

Save theotherzach/5826681 to your computer and use it in GitHub Desktop.
I have become Brian Muller
class User < ActiveRecord::Base
geocoded_by :address
def save_with_geocode
geocode if address_changed?
save
end
def address
address_compenents.map { |e| self.send e }.join(" ")
end
def address_changed?
address_compenents.inject(false) { |bool,e|
bool || self.send("#{e}_changed?")
}
end
private
def address_compenents
%w{address_line_1 address_line_2 city state zip_code}
end
end
@theotherzach

Copy link
Copy Markdown
Author

Ohhhh, good call on the 'any?'. I had also considered making the address components a constant just to clarify that yes, this is just data storage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment