Module: RailsCom::Translation
- Defined in:
- lib/rails_com/active_record/translation.rb
Instance Method Summary collapse
- #_update_record(values, constraints) ⇒ Object
-
#has_translations(*columns) ⇒ Object
name * store as jsonb in database; * read with i18n scope.
Instance Method Details
#_update_record(values, constraints) ⇒ Object
56 57 58 59 60 |
# File 'lib/rails_com/active_record/translation.rb', line 56 def _update_record(values, constraints) mattr_accessor :i18n_attributes values.except!(*i18n_attributes) super end |
#has_translations(*columns) ⇒ Object
name
-
store as jsonb in database;
-
read with i18n scope
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rails_com/active_record/translation.rb', line 34 def has_translations(*columns) mattr_accessor :i18n_attributes self.i18n_attributes = columns.map(&:to_s) include RailsCom::I18n columns.each do |column| attribute column, :i18n class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def #{column}=(value) if value.is_a?(String) super(::I18n.locale.to_s => value) else super end end RUBY_EVAL end end |