Class: DynamicFieldsets::FieldDefault

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/dynamic_fieldsets/field_default.rb

Overview

Base class for various field_defaults, A text field would have a single default value While a multiple select could have multiple default values

Instance Method Summary collapse

Instance Method Details

#convert_option_name_to_idObject

When the field type is an option type, the saved value should be converted into an id This needs to happen because the value field normally stores a string but sometimes stores a field option id

In some cases, the field_option instance is not set before this, no idea what happens then

www.youtube.com/watch?v=BeP6CpUnfc0



23
24
25
26
27
28
# File 'app/models/dynamic_fieldsets/field_default.rb', line 23

def convert_option_name_to_id
  if field.uses_field_options?
    option = FieldOption.where(:name => self.value, :field_id => self.field.id).first
    self.value = option.id unless option.nil?
  end
end

#pretty_valueString

Returns Either the value or the name of the field option reference by the value.

Returns:

  • (String)

    Either the value or the name of the field option reference by the value



31
32
33
34
35
36
37
38
39
# File 'app/models/dynamic_fieldsets/field_default.rb', line 31

def pretty_value
  if !self.field.nil? && field.uses_field_options?
    option = FieldOption.find(self.value)
    if !option.nil?
      return option.name
    end
  end
  return self.value
end