2
votes

I am using the master branch of Carrierwave and using the mount_uploaders method. I can use the mount_uploader method and upload individual images, just not when using multiple.

I am receiving this message and can't narrow down what the problem is exactly.

After saving, on both Create and Update I receive:

NoMethodError

undefined method `map' for #<ActionDispatch::Http::UploadedFile:0x007fd281d6cdc8>

Parameter Request:

"award_images"=>#<ActionDispatch::Http::UploadedFile:0x007fd281d6cdc8 @tempfile=#<Tempfile:/var/folders/zx/47b5lzf16312zkh6949lm1_80000gq/T/RackMultipart20150210-22178-x4x4h9>,
 @original_filename="2009_01_addy_cfgc_videos.jpg",

Using json column - award_images:json

View: _form

<h2>Featured Image</h2>
<p>
     <%= image_tag(@award.award_images_url, :class => "image img-responsive featured") if @award.award_images? %> 
    <%= f.file_field :award_images, multiple: true, name: "award[award_images]" %>
    <%= f.hidden_field :award_images_cache %>
    </p>

    <p>
<label>
  <%= f.check_box :remove_award_images %>
  Remove Images
</label>
    </p>

Model:

class Award < ActiveRecord::Base
mount_uploaders :award_images, AwardImageUploader
end

Controller: My strong params

private

def award_params
params.require(:award).permit(:title, :award_images, :etc)
end

Extra Details:

Rails 4.1.8

Ruby 2.1.2

Postgres

2

2 Answers

1
votes

Official whitelisting of params is slightly different. The multiple uploads should be whitelisted as {variables: []}. Try the following:

def award_params
   params.require(:award).permit(:title, {award_images: []}, :etc)
end

source

0
votes

In your view file try different name:

<%= f.file_field :award_images, multiple: true, name: "award[award_images][]" %>

The brackets indicate that the input field is an array (more than one image).