1

I have Rails 4 + CarrierWave + Nested form for Ad model which as many Image (mount PictureUploader as picture)

When I try to add or edit Ad, I have unpermitted parameters picture

Parameters: {"utf8"=>"✓", 
"ad"=>{
   "title"=>"plot", 
   "images_attributes"=>
      { "0" => 
         { 
            "picture"=>[#<ActionDispatch::Http::UploadedFile:0x007fbea1ddedb8 @tempfile=#<Tempfile:/var/folders/t8/fm77jh7j6232v5km2llkgq1r0000gn/T/RackMultipart20140921-33609-54hs6k>, @original_filename="New-york-rental-apartment-1-.gif", @content_type="image/gif", @headers="Content-Disposition: form-data; name=\"ad[images_attributes][0][picture][]\"; filename=\"New-york-rental-apartment-1-.gif\"\r\nContent-Type: image/gif\r\n">],
            "_destroy"=>"false"
         }
      }
   }
}

Unpermitted parameters: parent_id
Unpermitted parameters: parent_id
Unpermitted parameters: picture

I permitted the param with following. (according to this Rails Guide, my code should be working)

params.require(:ad).permit(:picture, :title, :images_attributes => [:picture, :id, :_destroy])

I only get fallback picture from carrierwave and now I'm clueless.

EDIT 1:

Found this issue on github discussing about Carrierwave not working with nested forms.

Also found A complete sample of how to perform nested polymorphic uploads in rails using carrierwave. It is in Rails 3 and I haven't tested it yet.

Tun
  • 1,345
  • 13
  • 34

1 Answers1

0

I was following tutorials after tutorials and messed up my code. A complete sample of how to perform nested polymorphic uploads in rails using carrierwave works.

I was using nested_form and configure file to accept multiple files. I changed my each file input to accept only one and it is now working.

Tun
  • 1,345
  • 13
  • 34