Module: Unidom::Common::Concerns::ModelExtension::ClassMethods

Defined in:
app/models/unidom/common/concerns/model_extension.rb

Instance Method Summary collapse

Instance Method Details

#to_code(code) ⇒ Object

将模型对象或者 code 转换成 code 。如: to_id(category) # category.id to_id(category.code) # category.id



172
173
174
# File 'app/models/unidom/common/concerns/model_extension.rb', line 172

def to_code(code)
  code.respond_to?(:code) ? code.code : code
end

#to_id(model) ⇒ Object

将模型对象或者 ID 转换成 ID 。如: to_id(person) # person.id to_id(person.id) # person.id



164
165
166
# File 'app/models/unidom/common/concerns/model_extension.rb', line 164

def to_id(model)
  model.respond_to?(:id) ? model.id : model
end