diff options
| author | Xinhui | 2017-09-27 11:59:44 +0200 | 
|---|---|---|
| committer | Xinhui | 2017-09-27 15:39:16 +0200 | 
| commit | c3f80c537e28dfe316ee0dcbee2bde2b5307fd79 (patch) | |
| tree | 8dc067d2b7cd378d03be8f9d19f46fff542ec8d6 | |
| parent | b64a51db2cff7aed22ef9eabb8210905cbe9d626 (diff) | |
| download | chouette-core-c3f80c537e28dfe316ee0dcbee2bde2b5307fd79.tar.bz2 | |
Support of dynamic_attributes in form
Refs #4467
| -rw-r--r-- | app/controllers/compliance_controls_controller.rb | 10 | ||||
| -rw-r--r-- | app/models/generic_attribute_min_max.rb | 18 | ||||
| -rw-r--r-- | app/views/compliance_controls/_form.html.slim | 4 | 
3 files changed, 21 insertions, 11 deletions
| diff --git a/app/controllers/compliance_controls_controller.rb b/app/controllers/compliance_controls_controller.rb index 20f4b15af..71d702945 100644 --- a/app/controllers/compliance_controls_controller.rb +++ b/app/controllers/compliance_controls_controller.rb @@ -5,7 +5,7 @@ class ComplianceControlsController < BreadcrumbController    def new      @compliance_control_set = parent -    @compliance_control = ComplianceControl.new +    @compliance_control = GenericAttributeMinMax.new      @compliance_control.build_compliance_control_block    end @@ -15,7 +15,13 @@ class ComplianceControlsController < BreadcrumbController    end    private +  def dynamic_attributes_params +    params.require(:compliance_control).permit(:type).values[0].constantize.dynamic_attributes +  end +    def compliance_control_params -    params.require(:compliance_control).permit(:name, :code, :criticity, :comment, :control_attributes, :type, compliance_control_block_attributes: [:name, :transport_mode]) +    base = [:name, :code, :criticity, :comment, :control_attributes, :type, compliance_control_block_attributes: [:name, :transport_mode]] +    permited = base + dynamic_attributes_params +    params.require(:compliance_control).permit(permited)    end  end diff --git a/app/models/generic_attribute_min_max.rb b/app/models/generic_attribute_min_max.rb index 8e85834a8..91bf285f0 100644 --- a/app/models/generic_attribute_min_max.rb +++ b/app/models/generic_attribute_min_max.rb @@ -1,23 +1,23 @@  class GenericAttributeMinMax < ComplianceControl - -    hstore_accessor :control_attributes, minimum: :integer, maximum: :integer -  #attribute :minimum, type: :integer, optionnal: true -  #attribute :maximum, type: :integer, optionnal: true -  #attribute :target, type: ModelAttribute    @@default_criticity = :warning    @@default_code = "3-Generic-2"    validate :min_max_values +    def min_max_values      true    end -  after_initialize do -    self.name = 'GenericAttributeMinMax' -    self.code = @@default_code -    self.criticity = @@default_criticity +  def self.dynamic_attributes +    self.hstore_metadata_for_control_attributes.keys    end +  # after_initialize do +  #   self.name = 'GenericAttributeMinMax' +  #   self.code = @@default_code +  #   self.criticity = @@default_criticity +  # end +  end diff --git a/app/views/compliance_controls/_form.html.slim b/app/views/compliance_controls/_form.html.slim index 9ee2dec69..c9e1c0fcc 100644 --- a/app/views/compliance_controls/_form.html.slim +++ b/app/views/compliance_controls/_form.html.slim @@ -7,6 +7,10 @@        = f.input :criticity        = f.input :comment +      - f.object.class.dynamic_attributes.each do |attribute| +        = f.input attribute.to_sym +      end +        = f.simple_fields_for :compliance_control_block do |c|          = c.input :name          = c.input :transport_mode, as: :select, collection:StifTransportModeEnumerations.transport_mode.options | 
