Class: Mobility::Backends::ActiveRecord::Column
- Inherits:
-
Object
- Object
- Mobility::Backends::ActiveRecord::Column
- Includes:
- Mobility::Backends::ActiveRecord, Column
- Defined in:
- lib/mobility/backends/active_record/column.rb
Overview
Implements the Column backend for ActiveRecord models.
You can use the mobility:translations generator to create a migration adding
translatable columns to the model table with:
rails generate mobility:translations post title:string
The generated migration will add columns title_<locale> for every locale in
I18n.available_locales. (The generator can be run again to add new attributes
or locales.)
Defined Under Namespace
Classes: QueryMethods
Backend Accessors collapse
-
#read(locale, _ = {}) ⇒ Object
Gets the translated value for provided locale from configured backend.
-
#write(locale, value, _ = {}) ⇒ Object
Updates translation for provided locale without calling backend's methods to persist the changes.
Instance Method Summary collapse
-
#each_locale {|Locale| ... } ⇒ Object
Yields locales available for this attribute.
Methods included from Column
#column, column_name_for, included
Methods included from Mobility::Backend::OrmDelegator
Methods included from Mobility::Backends::ActiveRecord
included, #setup_query_methods
Instance Method Details
#each_locale {|Locale| ... } ⇒ Object
Yields locales available for this attribute.
50 51 52 |
# File 'lib/mobility/backends/active_record/column.rb', line 50 def each_locale available_locales.each { |l| yield(l) if present?(l) } end |
#read(locale, _ = {}) ⇒ Object
Gets the translated value for provided locale from configured backend.
39 40 41 |
# File 'lib/mobility/backends/active_record/column.rb', line 39 def read(locale, _ = {}) model.read_attribute(column(locale)) end |
#write(locale, value, _ = {}) ⇒ Object
Updates translation for provided locale without calling backend's methods to persist the changes.
44 45 46 |
# File 'lib/mobility/backends/active_record/column.rb', line 44 def write(locale, value, _ = {}) model.send(:write_attribute, column(locale), value) end |