【发布时间】:2017-10-23 18:06:53
【问题描述】:
我的模型有三列用于上传图片和文档。我正在使用Rails 5.1.4 和Carrierwave 1.0。我不想要一个接受多个上传作为数组的列,所以我决定只有三个单独的上传选项,并尝试使用同一个上传器。
我不断收到 [:photo_one, :photo_two, :photo_three]:Array 的 undefined methodto_sym' 你的意思是? to_s to_yaml to_set` 错误,经过数小时的搜索似乎无法弄清楚。我确实感觉我的上传者错了,但我目前的知识水平很难确定。
models/plaqueorder.rb
class Plaqueorder < ApplicationRecord
mount_uploader [:photo_one, :photo_two, :photo_three], DocumentUploader
belongs_to :user
end
uploaders/document_uploader.rb
class DocumentUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}"
end
version :thumb do
process resize_to_fit: [100, 50]
end
def extension_white_list
%w(jpg jpeg gif png pdf)
end
end
【问题讨论】:
-
你可以在那里使用数组吗?文档通过 3 次调用 mount_uploader 来做到这一点...rubydoc.info/github/jnicklas/carrierwave/…
标签: ruby-on-rails ruby ruby-on-rails-5 carrierwave