Module: RailsCom::I18n
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/rails_com/active_record/translation.rb
Instance Method Summary collapse
Instance Method Details
#attributes_with_values_for_create(attribute_names) ⇒ Object
19 20 21 22 23 24 25 |
# 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 ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# 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 |