Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/human_attribute/active_record/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.human_attribute_value(attribute_name, value) ⇒ Object

en.activerecord.attribute_values.class_name.attribute_name Example I18n lookup: en.activerecord.attribute_values.user.state



6
7
8
9
10
11
12
# File 'lib/human_attribute/active_record/base.rb', line 6

def self.human_attribute_value(attribute_name, value)
  if value.present?
    I18n.t(value, :scope => "activerecord.attribute_values.#{self.name.underscore}.#{attribute_name}")
  else
    value
  end
end

Instance Method Details

#human_name(attribute_name) ⇒ Object

Looks in en.activerecord.attributes.class.attribute_name Example I18n lookup: en.activerecord.attributes.user.state



16
17
18
# File 'lib/human_attribute/active_record/base.rb', line 16

def human_name(attribute_name)
  self.class.human_attribute_name(attribute_name)
end

#human_value(attribute_name) ⇒ Object

en.activerecord.attribute_values.class_name.attribute_name Example I18n lookup: en.activerecord.attribute_values.user.state



22
23
24
25
# File 'lib/human_attribute/active_record/base.rb', line 22

def human_value(attribute_name)
  value = send(attribute_name)
  self.class.human_attribute_value attribute_name, value
end