Class: Globalize::ActiveRecord::Translation
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Globalize::ActiveRecord::Translation
- Defined in:
- lib/globalize/active_record/translation.rb
Class Method Summary collapse
-
.table_exists? ⇒ Boolean
Sometimes ActiveRecord queries .table_exists? before the table name has even been set which results in catastrophic failure.
- .translated_locales ⇒ Object
- .with_locales(*locales) ⇒ Object (also: with_locale)
Instance Method Summary collapse
Class Method Details
.table_exists? ⇒ Boolean
Sometimes ActiveRecord queries .table_exists? before the table name has even been set which results in catastrophic failure.
11 12 13 |
# File 'lib/globalize/active_record/translation.rb', line 11 def table_exists? table_name.present? && super end |
.translated_locales ⇒ Object
23 24 25 |
# File 'lib/globalize/active_record/translation.rb', line 23 def translated_locales select('DISTINCT locale').order(:locale).map(&:locale) end |
.with_locales(*locales) ⇒ Object Also known as: with_locale
15 16 17 18 19 20 |
# File 'lib/globalize/active_record/translation.rb', line 15 def with_locales(*locales) # Avoid using "IN" with SQL queries when only using one locale. locales = locales.flatten.map(&:to_s) locales = locales.first if locales.one? where :locale => locales end |
Instance Method Details
#locale ⇒ Object
28 29 30 31 |
# File 'lib/globalize/active_record/translation.rb', line 28 def locale _locale = read_attribute :locale _locale.present? ? _locale.to_sym : _locale end |
#locale=(locale) ⇒ Object
33 34 35 |
# File 'lib/globalize/active_record/translation.rb', line 33 def locale=(locale) write_attribute :locale, locale.to_s end |