My rails' app has uploading images function.
Precompiled assets will be created in public/assets When I deploy rails app in production and run
RAILS_ENV=production rake assets:precompile
I will get below error messages every time user upload images successfully in admin platform and request showing that created image.
ActionView::Template::Error (The asset "course/main_photo/XXXX/Course_ss12344.png"
is not present in the asset pipeline.):
In those messages, I found that images created by user didn't precompile in the public/assets.
config.assets.compile = true # when I set true for config.assets.compile, server will response assets slowly that is not good choice.
config/environments/production.rb # below is my relative code in production's config
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
config.serve_static_assets = true
Can anyone give me some advice on how to auto precompile assets or other advice when user upload images online?
course/main_photo/XXXX/Course_ss12344.png
an image you expect to exist? Or being uploaded by a user? How is the image link from the view? – spickermanncourse/main_photo/XXXX/Course_ss12344.png
<-- that is user created. I created course admin page for user to upload their course and relative images. The path of image uploading will created inapp/assets/images/course/main_photo/model_id/xxx.png
. Yes, image link is from view. – Tiger oilimage_path(course/main_photo/xxxx/xxx.png)
. I can sure that these images uploaded by user exist inapp/assets/images/course/xxxx/
. I am wondering thatassets.compile
setting to false alwayse search forpublic/assets/course/main_photo/xxxx/encoded_name.png
. Means that the new created images by user in production must run again rake assets command to rebuild that images inpublic/assets/....
. How the people do automatically(run by rails or doing some tricky way ) precompile assets. – Tiger oilpublic/system
folder. And more importable that user uploads do not get delivered via the asset pipeline. This approach fights against common Rails conventions (see the Rails Guide about user uploads) and is error-prone (What if that file does not exist? What if you want to use an environment like Heroku or multiple servers?). This sounds like a xy problem to me. – spickermann