问题
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 useimage_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