Module: Lipsiadmin::DataBase::TranslateAttributes

Defined in:
lib/data_base/translate_attributes.rb

Overview

With this method we can translate define and automatically translate columns for the current rails locale.

Defining some columns like these:

m.col :string, :name_it, :name_en, :name_cz
m.col :text, :description_it, :description_en, :description_cz

we can call

myinstance.name

or

puts myinstance.description

Lipsiadmin look for name_#I18n.locale

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments) ⇒ Object

Define method missing to intercept calls to non-localized methods (eg. name instead of name_cz)



23
24
25
26
27
# File 'lib/data_base/translate_attributes.rb', line 23

def method_missing(method_name, *arguments)
  # puts "Trying to send '#{method_name}_#{I18n.locale}' to #{self.class}" # uncomment for easy debugging in script/console
  return self.send(:"#{method_name}_#{I18n.locale}") if self.respond_to?(:"#{method_name}_#{I18n.locale}")
  super
end