Sha256: 30a53e5bd822d3073bd96ef3ee1f8f6560c3cbfb0c24db2dac6c88b919b556ed

Contents?: true

Size: 781 Bytes

Versions: 90

Compression:

Stored size: 781 Bytes

Contents

module Fields::SuperSelectSupport
  extend ActiveSupport::Concern

  def assign_select_options(strong_params, attribute)
    attribute = attribute.to_s
    # We check for nil here because an empty array isn't `present?`, but we want to assign empty arrays.
    if strong_params.key?(attribute) && !strong_params[attribute].nil?
      # filter out the placeholder inputs that arrive along with the form submission.
      strong_params[attribute] = strong_params[attribute].select(&:present?)
    end
  end

  def create_model_if_new(id)
    if id.present?
      unless /^\d+$/.match?(id)
        id = yield(id).id.to_s
      end
    end
    id
  end

  def create_models_if_new(ids)
    ids.map do |id|
      create_model_if_new(id) do
        yield(id)
      end
    end
  end
end

Version data entries

90 entries across 90 versions & 1 rubygems

Version Path
bullet_train-fields-1.6.3 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.6.2 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.6.1 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.6.0 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.5.2 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.5.1 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.5.0 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.4.11 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.4.10 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.4.9 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.4.8 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.4.7 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.4.6 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.4.5 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.4.4 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.4.3 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.4.2 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.4.1 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.4.0 app/controllers/concerns/fields/super_select_support.rb
bullet_train-fields-1.3.25 app/controllers/concerns/fields/super_select_support.rb