Question

I have used carrierwave in my application, but some reason I am getting this error --> Unpermitted parameters: avatar even thought I have permitted params.

I am using nested_form with Single Table Inheritance

here are the codes --> removed_url

and here are the server logs:

Started POST "/alerts" for 127.0.0.1 at 2014-05-05 15:44:51 -0500
    Processing by AlertsController#create as HTML
      Parameters: {"utf8"=>"✓", "authenticity_token"=>"jRaArdof0tbBHCXmdPqNiNpainmqliIx0sS9HdaBEcw=", "alert"=>{"victims_attributes"=>{"0"=>{"first_name"=>"victim1", "last_name"=>"victim1", "race"=>"race", "gender"=>"gender", "hair_color"=>"black", "eye_color"=>"black", "height_ft"=>"12", "height_inch"=>"12", "age"=>"12", "age_unit"=>"month", "birth_date"=>"05/02/2014", "weight"=>"125", "additional_info"=>"125", "images_attributes"=>{"0"=>{"avatar"=>[#<ActionDispatch::Http::UploadedFile:0x00000007f23350 @tempfile=#<Tempfile:C:/Users/jk12907/AppData/Local/Temp/RackMultipart20140505-56936-1neutn>, @original_filename="IMG_4470.JPG", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"alert[victims_attributes][0][images_attributes][0][avatar][]\"; filename=\"IMG_4470.JPG\"\r\nContent-Type: image/jpeg\r\n">]}}, "_destroy"=>"false"}}, "created_at"=>"2014/05/07 15:43", "nic"=>"nic", "investigating_officer_name"=>"officername", "investigating_officer_title"=>"officername", "investigating_officer_phone"=>"officername", "agency_name"=>"agencyname", "agency_phone"=>"agencyphone", "reporting_agency_phone"=>"agencyphone", "reporting_agency_email"=>"agencyemail", "last_seen"=>"2014/05/06 15:43", "last_known_address"=>"address", "last_known_city"=>"city", "last_known_state"=>"state", "last_known_county"=>"travis", "last_known_zip"=>"78660", "site_of_incident"=>"site of incident", "suspects_attributes"=>{"0"=>{"first_name"=>"suspect", "last_name"=>"suspect", "race"=>"asian", "gender"=>"male", "hair_color"=>"black", "eye_color"=>"black", "height_ft"=>"12", "height_inch"=>"45", "age"=>"12", "age_unit"=>"months", "birth_date"=>"05/02/2014", "weight"=>"145", "additional_info"=>"add info", "_destroy"=>"false"}}, "vehicles_attributes"=>{"0"=>{"make"=>"ford", "model"=>"ford", "style"=>"make", "year"=>"1995", "color"=>"black", "license_plate_number"=>"TYX", "license_plate_state"=>"TX", "additional_info"=>"add info", "_destroy"=>"false"}}}, "commit"=>"Create Alert"}
      User Load (1.0ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 8  ORDER BY "users"."id" ASC LIMIT 1
    Unpermitted parameters: avatar
       (0.0ms)  BEGIN
      SQL (0.0ms)  INSERT INTO "alerts" ("agency_name", "agency_phone", "created_at", "investigating_officer_name", "investigating_officer_phone", "investigating_officer_title", "last_known_address", "last_known_city", "last_known_county", "last_known_state", "last_known_zip", "last_seen", "nic", "reporting_agency_email", "reporting_agency_phone", "site_of_incident", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) RETURNING "id"  [["agency_name", "agencyname"], ["agency_phone", "agencyphone"], ["created_at", "2014-05-07 15:43:00.000000"], ["investigating_officer_name", "officername"], ["investigating_officer_phone", "officername"], ["investigating_officer_title", "officername"], ["last_known_address", "address"], ["last_known_city", "city"], ["last_known_county", "travis"], ["last_known_state", "state"], ["last_known_zip", "78660"], ["last_seen", "2014-05-06 15:43:00.000000"], ["nic", "nic"], ["reporting_agency_email", "agencyemail"], ["reporting_agency_phone", "agencyphone"], ["site_of_incident", "site of incident"], ["updated_at", "2014-05-05 20:44:51.406138"]]
      SQL (1.0ms)  INSERT INTO "vehicles" ("additional_info", "alert_id", "color", "created_at", "license_plate_number", "license_plate_state", "make", "model", "style", "updated_at", "year") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING "id"  [["additional_info", "add info"], ["alert_id", 23], ["color", "black"], ["created_at", "2014-05-05 20:44:51.409138"], ["license_plate_number", "TYX"], ["license_plate_state", "TX"], ["make", "ford"], ["model", "ford"], ["style", "make"], ["updated_at", "2014-05-05 20:44:51.409138"], ["year", 1995]]
      SQL (0.0ms)  INSERT INTO "people" ("additional_info", "age", "age_unit", "alert_id", "birth_date", "created_at", "eye_color", "first_name", "gender", "hair_color", "height_ft", "height_inch", "last_name", "race", "type", "updated_at", "weight") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) RETURNING "id"  [["additional_info", "125"], ["age", 12], ["age_unit", "month"], ["alert_id", 23], ["birth_date", "2014-02-05"], ["created_at", "2014-05-05 20:44:51.411138"], ["eye_color", "black"], ["first_name", "victim1"], ["gender", "gender"], ["hair_color", "black"], ["height_ft", 12], ["height_inch", 12], ["last_name", "victim1"], ["race", "race"], ["type", "Victim"], ["updated_at", "2014-05-05 20:44:51.411138"], ["weight", 125]]
      SQL (0.0ms)  INSERT INTO "images" ("created_at", "person_id", "updated_at") VALUES ($1, $2, $3) RETURNING "id"  [["created_at", "2014-05-05 20:44:51.414138"], ["person_id", 42], ["updated_at", "2014-05-05 20:44:51.414138"]]
      SQL (0.0ms)  INSERT INTO "people" ("additional_info", "age", "age_unit", "alert_id", "birth_date", "created_at", "eye_color", "first_name", "gender", "hair_color", "height_ft", "height_inch", "last_name", "race", "type", "updated_at", "weight") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) RETURNING "id"  [["additional_info", "add info"], ["age", 12], ["age_unit", "months"], ["alert_id", 23], ["birth_date", "2014-02-05"], ["created_at", "2014-05-05 20:44:51.416138"], ["eye_color", "black"], ["first_name", "suspect"], ["gender", "male"], ["hair_color", "black"], ["height_ft", 12], ["height_inch", 45], ["last_name", "suspect"], ["race", "asian"], ["type", "Suspect"], ["updated_at", "2014-05-05 20:44:51.416138"], ["weight", 145]]
       (19.0ms)  COMMIT
    Redirected to http://127.0.0.1:3000/alerts
    Completed 302 Found in 97ms (ActiveRecord: 21.0ms)

I have permitted the params in alerts_controller, people_controller and images_controller

and second question I have is, I have mention the dir to upload

def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

am I suppose to see image uploaded to 'uploads/' folder of my c drive? I have storage :file on my avatar_uploader.rb file

please let me know what I am doing wrong? First time using Carrierwave here

any helps appreciate

Was it helpful?

Solution

Remove :multiple => true option from alerts/app/views/alerts/_victim.html.erb

Currently, file_field for avatar looks like:

<%= p.file_field :avatar, :multiple => true, class:'form-control input-normal' %>

Your file_field should look like:

<%= p.file_field :avatar, class:'form-control input-normal' %>

With the :multiple => true option :avatar field is send as Array upon form submission.

But as per your params hash, you are not expecting an array so you receive an Unpermitted parameters: avatar

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top