How to change the format of Rails asset urls?

Background

I am currently working on a Rails 3 project that I intend to use with Amazon CloudFront with custom source code pointing to my actual web server. This means that my web server will tell the browser that it will retrieve static assets from CloudFront, if CloudFront has a cached resource, it will return it if it does not receive it, using the same path from my web server, and then cache it for future inquiries.

Problem

Amazon CloudFront discards and ignores query string parameters when determining whether it should overload its own cache to reload the asset from its source. This obviously creates a problem with the way Rails generates a URL-addresses via RAILS_ASSET_IDwhich must comply with: /assets/path/to/asset.ext?RAILS_ASSET_ID. With default URLs, CloudFront will hold obsolete assets for up to 24 hours.

Decision

What I hope to do somehow redefines how Rails 3 generates asset tags so that I can create URLs, for example /assets/RAILS_ASSET_ID/path/to/asset.ext. I already have a solution on how to get the web server to respond to these URLs, I just need to figure out how to get Rails to generate the URL.

Notes

  • My RAILS_ASSET_ID - git commit. capistrano . , ,
  • ActionView::Helpers::AssetTagHelper.rewrite_asset_path, , , , , , , .
  • !
+5
2

" ActionController::Base.config.asset_path proc, , , ."

AssetTagHelper .

+4

asset_id . Amazon S3 CloudFront.

+1

All Articles