Rails 4.0.3 generating incorrect asset paths with asset_sync

前端 未结 2 1125
你的背包
你的背包 2021-01-05 01:55

I have used the asset_sync gem many times before with great success, but using it in a Rails 4.0.3 project seems to have caused a problem.

The assets are uploaded, h

相关标签:
2条回答
  • 2021-01-05 02:19

    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.

    0 讨论(0)
  • 2021-01-05 02:41

    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!

    0 讨论(0)
提交回复
热议问题