Class: Para::AttributeField::EnumField

Inherits:
AttributeField::Base
  • Object
show all
Defined in:
lib/para/attribute_field/enum.rb

Instance Method Summary collapse

Instance Method Details

#field_typeObject



15
16
17
# File 'lib/para/attribute_field/enum.rb', line 15

def field_type
  :selectize
end

#value_for(instance) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/para/attribute_field/enum.rb', line 6

def value_for(instance)
  if (raw_value = instance.send(name)) &&
    path = enum_path_for(instance, raw_value)
    translation = ::I18n.t("activerecord.#{ path }", default: '')

    translation.presence || raw_value
  end
end