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.336 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.331 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.329 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.313 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.291 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.288 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.285 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.284 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.283 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.279 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.277 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.275 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.269 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.267 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.264 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.260 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.258 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.256 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.255 lib/lalala/ext_action_dispatch/multi_file_upload.rb
lalala-4.0.0.dev.254 lib/lalala/ext_action_dispatch/multi_file_upload.rb