我没有收到任何错误消息,一切似乎都很好但是你可以看到结果是国家模型商店的json列图像只是上传文件的最后一张图片。 我不明白为什么不工作。
这是我的国家/地区模型
class Country < ApplicationRecord
mount_uploader :photo, PhotoUploader
mount_uploaders :images, ImageUploader
serialize :images, JSON
geocoded_by :address
after_validation :geocode, if: :address_changed?
include PgSearch
pg_search_scope :search_name, :against => [:name]
end
这是我的ActiveAdmin模型国家/地区
ActiveAdmin.register Country do
permit_params :name, :description, :photo, :photo_cache, :address, :full_description, :best_period, :country, :latitude, :longitude, {images: []}
index do
selectable_column
column :name
column :description
column :created_at
actions
end
form :html => { :multipart => true } do |f|
f.inputs "Identity" do
f.input :name
f.input :images, as: :file, input_html: { multiple: true }
f.input :description
f.input :full_description
f.input :best_period
end
f.actions
end
end
我无法理解为什么我的图片列中只有一个商品商店
这是控制台日志
Started POST "/admin/countries" for ::1 at 2017-10-28 19:30:48 +0200
Processing by Admin::CountriesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"JUC+1egeOmL+fkyTMD8gjcGfEp6HCr8aY9ZG5SsV+ZSCOQq8gVweSXrva++8Bqh+UM42aVBhx1Oiib8fzFv+Jg==", "country"=>{"name"=>"South Africa", "images"=>[#<ActionDispatch::Http::UploadedFile:0x007faa611a4088 @tempfile=#<Tempfile:/var/folders/ql/2q1360r91vbbh0578gwtwgyc0000gn/T/RackMultipart20171028-849-18lgegy.jpg>, @original_filename="Afrique_du_sud - couverture.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"country[images][]\"; filename=\"Afrique_du_sud - couverture.jpg\"\r\nContent-Type: image/jpeg\r\n">, #<ActionDispatch::Http::UploadedFile:0x007faa611a4060 @tempfile=#<Tempfile:/var/folders/ql/2q1360r91vbbh0578gwtwgyc0000gn/T/RackMultipart20171028-849-1w04ibh.jpg>, @original_filename="Afrique_du_sud - photo1.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"country[images][]\"; filename=\"Afrique_du_sud - photo1.jpg\"\r\nContent-Type: image/jpeg\r\n">, #<ActionDispatch::Http::UploadedFile:0x007faa611c76f0 @tempfile=#<Tempfile:/var/folders/ql/2q1360r91vbbh0578gwtwgyc0000gn/T/RackMultipart20171028-849-11drf6n.jpg>, @original_filename="Afrique_du_sud - photo2.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"country[images][]\"; filename=\"Afrique_du_sud - photo2.jpg\"\r\nContent-Type: image/jpeg\r\n">, #<ActionDispatch::Http::UploadedFile:0x007faa611c7588 @tempfile=#<Tempfile:/var/folders/ql/2q1360r91vbbh0578gwtwgyc0000gn/T/RackMultipart20171028-849-1k00ol1.jpg>, @original_filename="Afrique_du_sud - photo3.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"country[images][]\"; filename=\"Afrique_du_sud - photo3.jpg\"\r\nContent-Type: image/jpeg\r\n">], "description"=>"Description", "full_description"=>"Full description", "best_period"=>"best period"}, "commit"=>"Create Country"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
(0.2ms) BEGIN
SQL (0.6ms) INSERT INTO "countries" ("created_at", "updated_at", "name", "description", "full_description", "best_period", "images") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["created_at", 2017-10-28 17:30:48 UTC], ["updated_at", 2017-10-28 17:30:48 UTC], ["name", "South Africa"], ["description", "Description"], ["full_description", "Full description"], ["best_period", "best period"], ["images", "\"[\\\"gmfhubfuzll8v8pjhjfv.jpg\\\",\\\"biyroewakmitexsphpup.jpg\\\",\\\"elmmtycn5aasd42xtvdr.jpg\\\",\\\"cqjsdccgrelaedanklve.jpg\\\"]\""]]
SQL (0.6ms) UPDATE "countries" SET "images" = '"\"image/upload/v1509211850/gmfhubfuzll8v8pjhjfv.jpg\""' WHERE "countries"."id" = $1 [["id", 80]]
SQL (0.4ms) UPDATE "countries" SET "images" = '"\"image/upload/v1509211854/biyroewakmitexsphpup.jpg\""' WHERE "countries"."id" = $1 [["id", 80]]
SQL (0.4ms) UPDATE "countries" SET "images" = '"\"image/upload/v1509211857/elmmtycn5aasd42xtvdr.jpg\""' WHERE "countries"."id" = $1 [["id", 80]]
SQL (0.5ms) UPDATE "countries" SET "images" = '"\"image/upload/v1509211859/cqjsdccgrelaedanklve.jpg\""' WHERE "countries"."id" = $1 [["id", 80]]
(6.0ms) COMMIT
Redirected to http://localhost:3000/admin/countries/80
Completed 302 Found in 12112ms (ActiveRecord: 9.0ms)
RESULT
[5] pry(main)> Country.first.images.length
Country Load (0.5ms) SELECT "countries".* FROM "countries" ORDER BY "countries"."id" ASC LIMIT $1 [["LIMIT", 1]]
=> 1