Last active
December 16, 2015 17:40
-
-
Save tkawa/5472222 to your computer and use it in GitHub Desktop.
This file contains 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 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