我通常一直使用Carrierwave和Rails< = 4,但我现在正在开发一个Rails 5项目。我无法上传图片而且我收到了多个错误(在ActiveAdmin中尝试过(未定义的方法图和种子文件)。 有谁知道错误在哪里?
使用的版本:
Ruby 2.4.1p111
Rails 5.02
Carrierwave 1.1.0
ActiveAdmin from Github Master Repo
像往常一样,我生成了我的上传器并将它们安装到我的模型中。
上传/ StoreImageUploader.rb
class StoreImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Create different versions of your uploaded files:
version :thumb do
process resize_to_fit: [250, 250]
end
end
模型/ store.rb
class Store < ApplicationRecord
mount_uploaders :image, StoreImageUploader
serialize :image, JSON # If you use SQLite, add this line.
belongs_to :organization
has_many :orders
end
通常,ActiveAdmin会自动检测到mounted uploaders
并将image:string
字段设置为:file
,但不是这次。
我手动调整了活动的管理文件。
系统管理员/ store.rb
ActiveAdmin.register Store do
permit_params :name , :image
form(:html => { :multipart => true }) do |f|
f.inputs "Store" do
f.input :name
f.input :image, :as => :file
end
f.button "Create"
end
end
答案 0 :(得分:0)
解决了,这是一个拼写错误setTimeout(function(){
document.getElementById('taginput').value = tempData[tempData.length - 1].trim();
},0);