Sha256: 6fe65ec2a4d9081447e7c690b624f984c711617613a1ebc8074d55ee5a0ec00a
Contents?: true
Size: 1.35 KB
Versions: 4
Compression:
Stored size: 1.35 KB
Contents
module DynamicFieldsets # Base class for various field_defaults, # A text field would have a single default value # While a multiple select could have multiple default values # # @authors Scott Sampson, Jeremiah Hemphill, Ethan Pemble class FieldDefault < ActiveRecord::Base self.table_name = "dynamic_fieldsets_field_defaults" #relations belongs_to :field #validations validates_presence_of :value before_save :convert_option_name_to_id # 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 # # http://www.youtube.com/watch?v=BeP6CpUnfc0 def convert_option_name_to_id if field.uses_field_options? option = FieldOption.find_by_name(self.value) self.value = option.id unless option.nil? end end # @return [String] Either the value or the name of the field option reference by the value def pretty_value if !self.field.nil? && field.uses_field_options? option = FieldOption.find_by_id(self.value) if !option.nil? return option.name end end return self.value end end end
Version data entries
4 entries across 4 versions & 1 rubygems