From d2ebfbde4fd28e3baa4bc0a0fe70448cff34502d Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Sun, 6 Jan 2013 06:34:16 -0600 Subject: [PATCH] added method location= and revised location to handle missing fields better --- lib/jam_ruby/models/user.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/jam_ruby/models/user.rb b/lib/jam_ruby/models/user.rb index 1af6ba2ab..0bf0c4400 100644 --- a/lib/jam_ruby/models/user.rb +++ b/lib/jam_ruby/models/user.rb @@ -106,7 +106,18 @@ module JamRuby end def location - return "#{self.city}, #{self.state}, #{self.country}" + loc = self.city.blank? ? '' : self.city + loc = loc.blank? ? self.state : "#{loc}, #{self.state}" unless self.state.blank? + loc = loc.blank? ? self.country : "#{loc}, #{self.country}" unless self.country.blank? + loc + end + + def location= location_hash + unless location_hash.blank? + self.city = location_hash[:city] + self.state = location_hash[:state] + self.country = location_hash[:country] + end if self.city.blank? end def should_validate_password?