asset_sync digest URLs not working on production
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!
Rails generate incorrect asset path with set 'config.assets.compile = false'
You need to execute RAILS_ENV=production rake assets:precompile
manually if the config.assets.compile
is set to false.
digest_path & asset_digest_path not allowing digest URLs
Hopefully this will help save my fellow programmer friends some head banging :D
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!
Set Expiry Headers asset_sync
Ok so i will answer this.. asset_sync will set cache_control and expiry dates on all assets that have been gzipped. I have noticed though that if some assets are being rendered from within a css file ( background image) then these images are not given any cache or expiry.
So within your asset_sync.rb file you can set custom headers like so
config.custom_headers = { '.*' => { cache_control: 'max-age=315576000', expires: 1.year.from_now.httpdate } }
Feel free to change the regular expression to match your files and change the cache_control and expiry dates.
A big thanks to Benjamin Darfler for pointing this out to me
Missing assets on production mode - passenger on nginx
Try using image-url
instead of url
.
background: #fff image-url('wallpaper.jpg') top left;
From the Asset Pipeline documentation:
When using the asset pipeline, paths to assets must be re-written and
sass-rails provides -url and -path helpers (hyphenated in Sass,
underscored in Ruby) for the following asset classes: image, font,
video, audio, JavaScript and stylesheet.
Related Topics
You Don't Have Write Permissions into the /Var/Lib/Gems/1.9.1 Directory
Regex to Validate String Having Only Characters (Not Special Characters), Blank Spaces and Numbers
Script to Run Against Stdin If No Arg; Otherwise Input File =Argv[0]
Creating a Test Suite Using Ruby Minitest
Cannot Load Such File -- Rack/Handler/Puma
How to Use Link_To to Link an Image and a Text
Error Running Heckle? 'Current_Code': Undefined Method 'Translate' for Ruby2Ruby
Detecting If This Is an Iframe Load or Direct
What Are Some Good Role Authorization Solutions Used with Authlogic
How to Programmatically Check If a Certificate Has Been Revoked
Ruby Ssl with Twitter Failed on Cert Openssl Issue on Windows 7
Many: 'Require': Cannot Load Such File -- "Gem_Name" (Loaderror) After Upgrade of Ruby/Rails
Why Is Throw and Catch Hardly Ever Used in Ruby
Alter $Path in Vim/Macvim So as to Find the Right Ruby Binary
Better Way to Write "Matching Balanced Parenthesis" Program in Ruby
Split a String into Chunks of Specified Size Without Breaking Words