上传图片到assets文件夹 [英] Uploading image into assets folder

查看:55
本文介绍了上传图片到assets文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照本指南使用 PaperClip 通过 ActiveAdmin 上传图像:使用纸夹通过 Activeadmin Rails 上传文件

I was following this guide for uploading images with PaperClip over ActiveAdmin: File upload with Activeadmin Rails using paperclip

一切正常,但我想知道,上传图片后,如何将其重定向到/assets/images/而不是仅在数据库中?

Everything is working fine, but I was wondering, after I upload image, how to redirect it to be uploaded into /assets/images/ instead only in database?

推荐答案

你没有.

无论如何都行不通.assets/images 是 rails 资产管道的源目录.在您的生产服务器上,图像不是从那里使用的,而是来自管道更新的另一个文件夹(通常获取带有链接时间戳的名称,以便浏览器可以正确缓存它们).

It won't work anyway. assets/images is a source directory for rails asset pipeline. On your production server, the images are not used from there but from another folder where they have been updated by the pipeline (typically getting a name with a linked timestamp, so that the browsers can cache them properly).

要完成这项工作,您需要将它们上传到资产/图像,然后再次运行资产管道,这会……很奇怪.

To make this work you would need to upload them to the assets/images, then run again the asset pipeline, which would be... weird.

如果您不想将它们存储在公共文件夹中,请查看像 S3 这样的外部存储(使用 Heroku 的示例:https://devcenter.heroku.com/articles/paperclip-s3).

If you don't want to store them in the public folder, look at an external storage like S3 (sample using Heroku: https://devcenter.heroku.com/articles/paperclip-s3).

这篇关于上传图片到assets文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆