Class: Para::AttributeField::EnumField

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

Instance Attribute Summary

Attributes inherited from Base

#field_method, #model, #name, #options, #type

Instance Method Summary collapse

Methods inherited from Base

#attribute_column_path, #determine_name_and_field_method!, #excerptable_value?, #field_name, field_option, #field_options, field_types, #initialize, #parse_input, register, #searchable?, #type?

Constructor Details

This class inherits a constructor from Para::AttributeField::Base

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