Module: ActiveRecord::Mlang

Included in:
Lang
Defined in:
lib/active_record/mlang.rb,
lib/active_record/mlang/lang.rb,
lib/active_record/mlang/text.rb,
lib/active_record/mlang/railtie.rb,
lib/active_record/mlang/lang_text.rb

Defined Under Namespace

Modules: ClassMethods, Text Classes: Lang, LangText, Railtie

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
# File 'lib/active_record/mlang.rb', line 7

def self.included(base)
  base.extend ClassMethods
  base.set_text_reflection
end

Instance Method Details

#text(locale = nil) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/active_record/mlang.rb', line 54

def text(locale=nil)
  locale ||= I18n.default_locale
  if lang = Lang[locale]
    texts.find_or_create_by(lang_id: lang.id)
  else
    nil
  end
end