Created
March 5, 2013 19:55
-
-
Save simonprev/5093673 to your computer and use it in GitHub Desktop.
R18n translations and go_i18n_field in 25 lines...
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
module Extensions | |
module Translatable | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def translations(*fields) | |
fields.each do |field| | |
define_method field do read_translate(field) end | |
define_method "#{field}=" do |value| write_translate(field, value) end | |
end | |
end | |
end | |
def read_translate(field) | |
read_attribute("#{field}_#{I18n.locale}") | |
end | |
def write_translate(field, value) | |
write_attribute("#{field}_#{I18n.locale}", value) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment