module RailsCom::I18n

Public Instance Methods

attributes_with_values_for_create(attribute_names) click to toggle source
Calls superclass method
# File lib/rails_com/active_record/translation.rb, line 19
def attributes_with_values_for_create(attribute_names)
  r = super
  r.slice(*i18n_attributes).each do |key, v|
    r[key] = public_send "#{key}_before_type_cast"
  end
  r
end
update_i18n_column() click to toggle source
# File lib/rails_com/active_record/translation.rb, line 8
def update_i18n_column
  str = []
  self.changes.slice(*i18n_attributes).each do |key, _|
    value = self.public_send("#{key}_before_type_cast")
    str << "#{key} = #{key}::jsonb || '#{value.to_json}'::jsonb"
  end
  return if str.blank?
  s = str.join(', ')
  self.class.connection.execute "UPDATE #{self.class.table_name} SET #{s} WHERE id = #{self.id}"
end