![](/img/trans.png)
[英]I am Using mongodb in rails and when use the carrierwave gem this thrown errors
[英]In Rails 5.2, using Carrierwave gem how can I use the default gem when the file no longer exists on disk?
我在Rails 5.2.2.1。上使用了Carrierwave gem。 当数据库中不存在用于该记录的图像时,我使用默认URL设置了该图像。 但是,如果我在数据库中有用于记录的图像,但是该文件在磁盘上不存在,该如何显示呢?
当前,我收到以下错误:
ActionController :: RoutingError(没有与[GET]匹配的路由“ /uploads/player/314c38a9-6567-4faa-bfda-9e7a75cbaed4.jpeg”)
有什么方法可以挽救并显示我在Uploader文件中指定的默认URL?
如果您有默认图片,则可以在模型中设置如下方法
def image
File.file?(file.path) ? file.url : default_image_url #and you need to define this default url
end
或者您可以在路线中以@mroach的形式处理404图像
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.