0
carrierwave를 사용하여 active_admin에서 여러 이미지를 업로드하려고했습니다. 그래서 캐리어 웨이브 문서에 따라 배열 필드를 가져 와서 중첩 필드를 허용하지만 여러 이미지를 업로드 한 후에 오류가 발생했습니다.여러 장의 이미지 업로드가 반송파로 작동하지 않습니다.
error:
AdminUser Load (0.7ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
(0.3ms) BEGIN
SQL (0.8ms) INSERT INTO "albums" ("title", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["title", "dvdfbfdbfdb"], ["created_at", 2016-08-10 18:36:56 UTC], ["updated_at", 2016-08-10 18:36:56 UTC]]
SQL (0.9ms) INSERT INTO "images" ("created_at", "updated_at", "avatars", "avatarable_id", "avatarable_type") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["created_at", 2016-08-10 18:36:56 UTC], ["updated_at", 2016-08-10 18:36:56 UTC], ["avatars", "{kfos6fofbk1pbhrw2a5x.png,meaxlow3fgehcoepklm7.jpg}"], ["avatarable_id", 22], ["avatarable_type", "Album"]]
SQL (1.8ms) UPDATE "images" SET "avatars" = 'image/upload/v1470854220/kfos6fofbk1pbhrw2a5x.png' WHERE "images"."id" = $1 [["id", 23]]
(0.3ms) ROLLBACK
Completed 500 Internal Server Error in 4632ms (ActiveRecord: 4.7ms)
ActiveRecord::StatementInvalid (PG::InvalidTextRepresentation: ERROR: malformed array literal: "image/upload/v1470854220/kfos6fofbk1pbhrw2a5x.png"
LINE 1: UPDATE "images" SET "avatars" = 'image/upload/v1470854220/kf...
^
DETAIL: Array value must start with "{" or dimension information.
: UPDATE "images" SET "avatars" = 'image/upload/v1470854220/kfos6fofbk1pbhrw2a5x.png' WHERE "images"."id" = $1):
activerecord (5.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:598:in `async_exec'
activerecord (5.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:598:in `block in exec_no_cache'
activerecord (5.0.0) lib/active_record/connection_adapters/abstract_adapter.rb:566:in `block in log'
activesupport (5.0.0) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activerecord (5.0.0) lib/active_record/connection_adapters/abstract_adapter.rb:560:in `log'
activerecord (5.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:598:in `exec_no_cache'
activerecord (5.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:587:in `execute_and_clear'
activerecord (5.0.0) lib/active_record/connection_adapters/postgresql/database_statements.rb:116:in `exec_delete'
activerecord (5.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:133:in `update'
activerecord (5.0.0) lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `update'
ActiveAdmin.register Album do
permit_params :title,images_attributes: [:id,:_destroy,:avatars=>[]]
form html: { multipart: true } do |f|
f.inputs do
f.input :title
f.has_many :images, allow_destroy: true do |a|
a.input :avatars, :as => :file ,input_html:{multiple: true}
end
end
f.actions
end
end
class Album < ApplicationRecord
has_many :images, as: :avatarable, dependent: :destroy
accepts_nested_attributes_for :images, :allow_destroy => true
end
class Image < ApplicationRecord
belongs_to :avatarable, polymorphic: true
mount_uploaders :avatars, AvatarUploader
end
# encoding: utf-8
class AvatarUploader < CarrierWave::Uploader::Base
include Cloudinary::CarrierWave
def extension_white_list
%w(jpg jpeg gif png)
end
end
감사 @Taragano을, 그러나 여기에서 나는 배열 유형 필드에 여러 개의 이미지를 저장하기 위해 노력하고,이 정답은 아니다. – TheVinspro
해결책을 찾을 수 있습니까? @Itay Taragano – TheVinspro