Uploading image into assets folder

2019-09-02 17:38发布

问题:

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

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?

回答1:

You don't.

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.

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).