Class: DynamicFieldsets::FieldDefault
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- DynamicFieldsets::FieldDefault
- 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
-
#convert_option_name_to_id ⇒ Object
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.
-
#pretty_value ⇒ String
Either the value or the name of the field option reference by the value.
Instance Method Details
#convert_option_name_to_id ⇒ Object
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
23 24 25 26 27 28 |
# File 'app/models/dynamic_fieldsets/field_default.rb', line 23 def convert_option_name_to_id if field. option = FieldOption.where(:name => self.value, :field_id => self.field.id).first self.value = option.id unless option.nil? end end |
#pretty_value ⇒ String
Returns 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. option = FieldOption.find(self.value) if !option.nil? return option.name end end return self.value end |