module RailsCom::Translation

Public Instance Methods

_update_record(values, constraints) click to toggle source
Calls superclass method
# 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) click to toggle source

name

  • store as jsonb in database;

  • read with i18n scope

# 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