Precompiling uploaded assets

微笑、不失礼 提交于 2020-01-03 05:06:16

问题


I have a rails 3.1 application where users upload pictures. I am storing them in /assets/images since that is the path image_tag looks for instead of public/images.

Everything works fine in development but I deployed to Heroku and it gives me this error:

ActionView::Template::Error (image_name.jpeg isn't precompiled)

What is the right way to handle such a situation? Is there a way to compile images after uploading or should I store them somewhere else?


回答1:


  • You must not use the filesystem on Heroku to store uploads.

  • You should not use image_path with uploaded images, since that assumes it is looking at the filesystem. If you use image_tag, you must pass a complete URL, not just an image name.




回答2:


Are you using carrierwave for your images uploads? You can store them on amazon S3 reasonably easy with carrier wave. Carrierwave instructions Other solutions have S3 storage easily accessible as well.

Heroku will NOT let you store files in the filesystem. Run

RAILS_ENV=production bundle exec rake assets:precompile

to compile you assets locally, add to git, and push to heroku but you cannot add images later via your application on heroku. If you upload them to the /temp folder they will stay there for a short while or until you re-deploy/update your code I believe.



来源:https://stackoverflow.com/questions/8663179/precompiling-uploaded-assets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!