Rails 4.0.3 generating incorrect asset paths with asset_sync

眉间皱痕 提交于 2019-11-30 20:10:07

You need to run everything assets related in production mode in rails 4.

for example:

rake assets:precompile RAILS_ENV=production

If you run it in the default mode (development) the hash would be different so rails leaves off the hash all together.

Also, you will want to do this before you start the server so it finds the files.

NOTE: I think this change was to allow you to cache assets in development.

Jonathan Reyes

Hopefully this will help save my fellow programmer friends some head banging :D. I have answered this question on "digest_path & asset_digest_path not allowing digest URLs" but will repost it here so it will save you some clicks.

I was uploading the files to S3, I didn't realize that the manifest wasn't loaded by Rails. You can have all your production settings right (like above and in other threads), but if you don't have the manifest.json file readable by Rails, it will still generate /javascript/* (example) urls.

I was still having trouble with multi_json gem's latest version, so I downgraded it to 1.7.8 and it works fine.

gem 'multi_json', '1.7.8'

That's so it can read the manifest.json file which rake assets:precompile creates.

There is a debate on this sprockets thread https://github.com/rails/sprockets-rails/issues/107 on whether your manifest file should be in git or just on a deploy script, do what suits you best, just make sure it is findable in:

/public/assets/manifest.json 

or specifiy it yourself with

config.assets.manifest = '...'

That may or may not be depricated.

Cheers!

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