我在我的应用程序中使用了carrierwave,但是有些原因我收到了这个错误 - > Unpermitted parameters: avatar
甚至认为我允许了参数。
我将nested_form
与Single Table Inheritance
这里是代码 - > removed_url
以下是服务器日志:
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)
我允许alerts_controller
,people_controller
和images_controller
我提到的第二个问题是,我已经提到要上传的目录
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
我想看到图片上传到我的c盘的'uploads/'
文件夹?我的avatar_uploader.rb文件中有storage :file
请让我知道我做错了什么?第一次在这里使用Carrierwave
任何有助于欣赏
答案 0 :(得分:2)
从:multiple => true
alerts/app/views/alerts/_victim.html.erb
选项
目前,file_field
的{{1}}似乎是:
avatar
您的<%= p.file_field :avatar, :multiple => true, class:'form-control input-normal' %>
应如下所示:
file_field
在提交表单时,<%= p.file_field :avatar, class:'form-control input-normal' %>
选项:multiple => true
字段将发送为:avatar
。
但是根据你的params哈希,你不期待一个数组,所以你收到Array