diff options
| author | Zog | 2018-03-16 14:36:47 +0100 |
|---|---|---|
| committer | Johan Van Ryseghem | 2018-04-04 11:10:39 +0200 |
| commit | 6f8bba2239c1717b3224e836eea0f9392fbb5c97 (patch) | |
| tree | ead29b582d7c960136c320f0dddc56ec64fd47f9 | |
| parent | d034376737c27e48a7a3413b82461a65999ee105 (diff) | |
| download | chouette-core-6f8bba2239c1717b3224e836eea0f9392fbb5c97.tar.bz2 | |
Refs #6184; Add default values to custom_fields
| -rw-r--r-- | app/models/concerns/custom_fields_support.rb | 3 | ||||
| -rw-r--r-- | app/models/custom_field.rb | 4 |
2 files changed, 7 insertions, 0 deletions
diff --git a/app/models/concerns/custom_fields_support.rb b/app/models/concerns/custom_fields_support.rb index 6565ac808..53be92b90 100644 --- a/app/models/concerns/custom_fields_support.rb +++ b/app/models/concerns/custom_fields_support.rb @@ -24,6 +24,9 @@ module CustomFieldsSupport def initialize_custom_fields self.custom_field_values ||= {} custom_fields.values.each &:initialize_custom_field + custom_fields.each do |k, v| + custom_field_values[k] ||= v.default_value + end end def custom_field_value key diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index a42f1651d..6236f482e 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -44,6 +44,10 @@ class CustomField < ActiveRecord::Base delegate :code, :name, :field_type, to: :@custom_field + def default_value + options["default"] + end + def options @custom_field.options || {} end |
