Sha256: ab395996d2896394e064dc8b166be64340b31d90eb376ea574a7bdbe18039f99

Contents?: true

Size: 691 Bytes

Versions: 18

Compression:

Stored size: 691 Bytes

Contents

module RefreshFieldsHelper
  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[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

18 entries across 18 versions & 1 rubygems

Version Path
bullet_train-fields-1.5.1 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.5.0 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.4.11 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.4.10 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.4.9 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.4.8 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.4.7 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.4.6 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.4.5 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.4.4 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.4.3 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.4.2 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.4.1 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.4.0 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.3.25 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.3.24 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.3.23 app/helpers/refresh_fields_helper.rb
bullet_train-fields-1.3.22 app/helpers/refresh_fields_helper.rb