我正在添加carrierwave_mongoid来存储图像,我已将图像保存到mongo 我的数据是这样的:
{ "contentType" : "image/jpeg", "length" : 512659, "chunkSize" : 4194304, "uploadDate" : ISODate("2013-01-26T00:00:00Z"), "md5" : "3d44aa8fcfba7cae34fe9a592407410b", "filename" : "uploads/deal/image/295/15a11db8e441c610330af53a77e2b136.jpg", "_id" : 5 }
我有一个故事模型:
class Deal
include Mongoid::Document
include Mongoid::Timestamps
field :image, :type => String
field :status, :type => Integer
mount_uploader :image, ImageUploader
end
我的ImageUploader代码在这里:
class ImageUploader < CarrierWave::Uploader::Base
...
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
现在我想显示来自mongodb的图像,并且在视图中我有
<%= image_tag(@deal.image.url) %>
最后图像不会显示在视图中并出现以下错误:
ActionController::RoutingError (No route matches [GET] "/assets/uploads/deal/image/295/15a11db8e441c610330af53a77e2b136.jpg"):
我想知道如何通过carrierwave_mongoid
读取图像答案 0 :(得分:0)
ActionController::RoutingError
表示您的rails应用程序无法处理此类请求。
定义到控制器的路由以查询gridfs并发送图像。此外,您可能需要将Nginx配置为不处理静态文件等请求。