Module: Mobility::Backends::Column
- Extended by:
- Mobility::Backend::OrmDelegator
- Included in:
- ActiveRecord::Column, Sequel::Column
- Defined in:
- lib/mobility/backends/column.rb
Overview
Stores translated attribute as a column on the model table. To use this
backend, ensure that the model table has columns named <attribute>_<locale>
for every locale in I18n.available_locales.
If you are using Rails, you can use the mobility:translations generator to
create a migration adding these 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.)
==Backend Options
There are no options for this backend. Also, the locale_accessors option will
be ignored if set, since it would cause a conflict with column accessors.
Class Method Summary collapse
-
.column_name_for(attribute, locale = Mobility.locale) ⇒ String
Returns name of column where translated attribute is stored.
- .included(base) ⇒ Object
Instance Method Summary collapse
-
#column(locale = Mobility.locale) ⇒ String
Returns name of column where translated attribute is stored.
Methods included from Mobility::Backend::OrmDelegator
Class Method Details
.column_name_for(attribute, locale = Mobility.locale) ⇒ String
Returns name of column where translated attribute is stored
41 42 43 44 |
# File 'lib/mobility/backends/column.rb', line 41 def self.column_name_for(attribute, locale = Mobility.locale) normalized_locale = Mobility.normalize_locale(locale) "#{attribute}_#{normalized_locale}".to_sym end |
.included(base) ⇒ Object
46 47 48 |
# File 'lib/mobility/backends/column.rb', line 46 def self.included(base) base.extend Backend::OrmDelegator end |
Instance Method Details
#column(locale = Mobility.locale) ⇒ String
Returns name of column where translated attribute is stored
33 34 35 |
# File 'lib/mobility/backends/column.rb', line 33 def column(locale = Mobility.locale) Column.column_name_for(attribute, locale) end |