Sha256: 54a60944ec1ce20b5f313614c443a2b01804bbc20cd556d770e926bfef5faf89

Contents?: true

Size: 709 Bytes

Versions: 13

Compression:

Stored size: 709 Bytes

Contents

module DependentFieldsFrameHelper
  def accept_query_string_override_for(form, method)
    field_name = form.field_name(method)

    new_value = new_value_from_query_string(field_name)
    return if new_value.nil?

    form.object.send(:"#{method}=", new_value)
  end

  private

  def new_value_from_query_string(field_name)
    params.dig(*params_dig_path_for_field_name(field_name))
  end

  def params_dig_path_for_field_name(field_name)
    dig_path = []

    nested_keys = Rack::Utils.parse_nested_query(field_name)

    while !nested_keys.nil? && nested_keys.keys.size
      key = nested_keys.keys.first
      dig_path << key.to_sym
      nested_keys = nested_keys[key]
    end

    dig_path
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bullet_train-fields-1.14.0 app/helpers/dependent_fields_frame_helper.rb
bullet_train-fields-1.13.0 app/helpers/dependent_fields_frame_helper.rb
bullet_train-fields-1.12.3 app/helpers/dependent_fields_frame_helper.rb
bullet_train-fields-1.12.2 app/helpers/dependent_fields_frame_helper.rb
bullet_train-fields-1.12.1 app/helpers/dependent_fields_frame_helper.rb
bullet_train-fields-1.12.0 app/helpers/dependent_fields_frame_helper.rb
bullet_train-fields-1.11.0 app/helpers/dependent_fields_frame_helper.rb
bullet_train-fields-1.10.0 app/helpers/dependent_fields_frame_helper.rb
bullet_train-fields-1.9.0 app/helpers/dependent_fields_frame_helper.rb
bullet_train-fields-1.8.5 app/helpers/dependent_fields_frame_helper.rb
bullet_train-fields-1.8.4 app/helpers/dependent_fields_frame_helper.rb
bullet_train-fields-1.8.3 app/helpers/dependent_fields_frame_helper.rb
bullet_train-fields-1.8.2 app/helpers/dependent_fields_frame_helper.rb