简体   繁体   中英

Rails 5 Carrierwave Uploader undefined method `to_sym' for [:photo_one, :photo_two, :photo_three]:Array Did you mean? to_s to_yaml to_set

My model has three columns I am using for image and document uploads. I am using Rails 5.1.4 and Carrierwave 1.0 . I don't want a single column that accepts multiple uploads as an array so I decided to just have three individual upload options and am trying to use the same uploader.

I keep getting a undefined method to_sym' for [:photo_one, :photo_two, :photo_three]:Array Did you mean? to_s to_yaml to_set` error and can't seem to figure it out after hours of searching. I do have an sense my uploader is wrong, but my current knowledge level is making it hard to tell for sure.

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

You need to define uploader for each field separately. If you will go through the mount_uploader sources you will see that array of colums not supported

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM