Sha256: 1c76c347a89cbf82428dd2dee6791edd2daec57500d15fa4c0aa2a81752beae2

Contents?: true

Size: 982 Bytes

Versions: 86

Compression:

Stored size: 982 Bytes

Contents

module Lalala::ExtActionDispatch::MultiFileUpload

private

  def normalize_parameters(value)
    value = super(value)

    if Hash === value
      value.each do |key, v|
        value[key] = correct_assets_hash_nesting(key, v)
      end
    end

    return value
  end

  def correct_assets_hash_nesting(key, value)
    unless key.to_s.ends_with?("_attributes")
      return value
    end

    unless Hash === value
      return value
    end

    if value.size == 0
      return value
    end

    last_id = value.keys.sort_by(&:to_i).last
    last_id = "#{last_id}"

    unless /^\d+$/ === last_id
      return value
    end

    assets  = value[last_id].try(:[], "asset")

    unless Array === assets
      return value
    end

    unless assets.all?{ |i| ActionDispatch::Http::UploadedFile === i }
      return value
    end

    assets.each do |file|
      value[last_id] = { "asset" => file }.with_indifferent_access
      last_id.succ!
    end

    return value
  end

end

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
lalala-4.0.0.dev.416 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.407 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.396 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.395 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.393 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.388 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.385 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.382 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.374 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.372 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.368 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.366 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.357 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.354 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.351 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.350 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.349 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.344 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.343 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.339 lib/lalala/ext_action_dispatch/multi_file_upload.rb