Skip to content

Instantly share code, notes, and snippets.

@tkawa
Last active December 16, 2015 17:40
Show Gist options
  • Save tkawa/5472222 to your computer and use it in GitHub Desktop.
Save tkawa/5472222 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
def postal_code1
postal_code.split('-', 2).first || ''
end
def postal_code2
postal_code.split('-', 2).second || ''
end
def postal_code1=(value)
splitted = postal_code.split('-', 2)
splitted[0] = value
self.postal_code = splitted.join('-')
end
def postal_code2=(value)
splitted = postal_code.split('-', 2)
splitted[1] = value
self.postal_code = splitted.join('-')
end
def locations=(value)
write_attribute(:locations, value.join(' '))
end
def locations
read_attribute(:locations).split(' ')
end
def locations_text
read_attribute(:locations)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment