【发布时间】:2021-12-10 20:05:05
【问题描述】:
Carrierwave 始终只保存第一张图片。它在“更新”操作后工作,但显示错误:
“图像/上传/”的未定义方法 `reject'
它在 db 的 jsonb 字段中存储了一个简单的只有一个文件路径的字符串。但是为什么会这样,我该如何解决呢?
模型中的代码:
mount_uploaders :images, ImageUploader
上传者代码:
class ImageUploader < CarrierWave::Uploader::Base
include Cloudinary::CarrierWave
CarrierWave.configure do |config|
config.cache_storage = :file
end
def extension_allowlist
%w(jpg jpeg gif png)
end
end
视图代码:
= f.input :images, label: t("photos"), as: :file, input_html: { multiple: true, class: "form-control"}
- @post.images.each do |image|
= hidden_field :post, :images, multiple: true, value: image.identifier
- if @post.images.any?
.form-group
%div.form-check
= f.check_box :remove_images, label: t("posts.remove_images"), class: "form-check-input", id: "removeImages"
%label.form-check-label{for: "removeImages"}
= t("posts.remove_images", count: @post.images.count)
【问题讨论】:
标签: ruby-on-rails ruby carrierwave