Module: RorHack::ActiveRecordBaseHack

Included in:
ActiveRecord::Base
Defined in:
lib/ror_hack/active_record_hack.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

返回某个枚举字段的英文对应的locales名称。



89
90
91
92
93
94
95
96
# File 'lib/ror_hack/active_record_hack.rb', line 89

def method_missing(method, *args, &block)
  method_name = method.to_s
  naked_name  = method_name.remove('_chinese_desc')
  if method_name.end_with?('_chinese_desc') && respond_to?(naked_name)
    return self.class.ming("#{ naked_name }.#{ self.send naked_name }")
  end
  super
end