Class: CustomField
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- CustomField
- Defined in:
- app/models/custom_field.rb
Overview
TODO The one problem I have with this is that when a field is empty, we still
save the record to the database. The difficulty is that when the
form is displayed, you need to have all the records there, ones that
were saved and empty ones for those not saved, all in the proper order.
This presents a challenge I'm not willing to tackle at this moment.
But it should be done so that the database isn't cluttered with needless
records.
Note: We serialize the data. This makes it easy to store checkbox arrays, dates, etc, without having to worry about munging the data first.
Instance Method Summary collapse
-
#checkbox_required ⇒ Object
——————————————————————————.
-
#initialize(*options, &block) ⇒ CustomField
constructor
——————————————————————————.
-
#value ⇒ Object
Returns a munged value depending on the field type.
Constructor Details
#initialize(*options, &block) ⇒ CustomField
45 46 47 48 |
# File 'app/models/custom_field.rb', line 45 def initialize(*, &block) super(*, &block) # prepare_data end |
Instance Method Details
#checkbox_required ⇒ Object
65 66 67 |
# File 'app/models/custom_field.rb', line 65 def checkbox_required errors.add(:field_data, :blank) if self.value.blank? end |
#value ⇒ Object
Returns a munged value depending on the field type. Used when data is exported.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/custom_field.rb', line 52 def value #--- if field is a country field, convert the country_id into real name if custom_field_def.field_type == 'country' Country.find(self.field_data.to_i).english_name elsif self.field_data.is_a? Array # make into a comma delimited string. remove any blank/nil entries self.field_data.reject {|x| x.blank?}.join(', ') else self.field_data end end |