Ruby on rails 4 Carrierwave+;ActiveAdmin,以文件和图像字段为例。结果是;“堆栈级别太深”;
我正在尝试在ActiveAdmin上创建一个文件和图像字段。例如 到目前为止我所拥有的Ruby on rails 4 Carrierwave+;ActiveAdmin,以文件和图像字段为例。结果是;“堆栈级别太深”;,ruby-on-rails-4,activeadmin,Ruby On Rails 4,Activeadmin,我正在尝试在ActiveAdmin上创建一个文件和图像字段。例如 到目前为止我所拥有的 创建迁移以将文件和图像列添加到数据库 创建活动管理和编辑的显示表单 创建模型 创建了2个上传程序 我的代码导致“堆栈级别太深”错误 奇怪的是,代码与我的示例完全相同,效果很好 管理/product.rb ActiveAdmin.register Product do permit_params :title, :image, :file form(:html => { :multipart
- 创建迁移以将文件和图像列添加到数据库
- 创建活动管理和编辑的显示表单
- 创建模型
- 创建了2个上传程序
ActiveAdmin.register Product do
permit_params :title, :image, :file
form(:html => { :multipart => true }) do |f|
f.inputs "Create Product..." do
f.input :title
f.input :image, :as => :file, :hint => f.template.image_tag(f.object.image.url(:thumb))
f.input :file, :as => :file
end
f.actions
end
end
class Product < ActiveRecord::Base
mount_uploader :file, FileProductsUploader
mount_uploader :image, ImageProductsUploader
end
class FileProductsUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"#{Rails.root}/public/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
class ImageProductsUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :file
def store_dir
"#{Rails.root}/public/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :resize_to_fit => [250, 250]
end
end
型号/产品.rb
ActiveAdmin.register Product do
permit_params :title, :image, :file
form(:html => { :multipart => true }) do |f|
f.inputs "Create Product..." do
f.input :title
f.input :image, :as => :file, :hint => f.template.image_tag(f.object.image.url(:thumb))
f.input :file, :as => :file
end
f.actions
end
end
class Product < ActiveRecord::Base
mount_uploader :file, FileProductsUploader
mount_uploader :image, ImageProductsUploader
end
class FileProductsUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"#{Rails.root}/public/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
class ImageProductsUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :file
def store_dir
"#{Rails.root}/public/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :resize_to_fit => [250, 250]
end
end
没有一个在线解决方案适合我。我解决了更改本地临时目录的错误 上传程序/*
def cache_dir
# should return path to cache dir
Rails.root.join 'tmp/uploads'
end
您在管理和产品模型中都有允许的参数。请删除模型中的
product\u params
方法,然后再试一次。允许的参数现在仅在管理中定义,但是堆栈级别太深的错误仍然存在。您可以在此添加堆栈错误跟踪吗?问题现在已用错误消息更新。@anusha我可以使用f.input:image,as::file,提示:f.template.image\u标记(f.object.image\u url)查看上载图像的预览
但是编辑表单上显示了一些垃圾文本,如#
如何解决此错误?