Skip to content

Instantly share code, notes, and snippets.

@simonprev
Created March 5, 2013 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonprev/5093673 to your computer and use it in GitHub Desktop.
Save simonprev/5093673 to your computer and use it in GitHub Desktop.
R18n translations and go_i18n_field in 25 lines...
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