module ActiveRecord::Mlang

Public Class Methods

included(base) click to toggle source
# File lib/active_record/mlang.rb, line 7
def self.included(base)
  base.extend ClassMethods
  base.set_text_reflection
end

Public Instance Methods

text(locale_or_lang_id=nil) click to toggle source
# File lib/active_record/mlang.rb, line 54
def text(locale_or_lang_id=nil)
  return nil if !self.persisted?

  locale_or_lang_id ||= I18n.locale || I18n.default_locale
  return nil if !(lang = Lang[locale_or_lang_id])

  texts.find_or_create_by(lang_id: lang.id)
end