Class: Sprockets::Redirect
- Inherits:
-
Object
- Object
- Sprockets::Redirect
- Defined in:
- lib/sprockets/redirect.rb
Overview
A Rack middleware for Rails >= 3.1.0 with asset pipeline and asset digest enabled. This middleware is used to redirect any request to static asset without a digest to the version with digest in its filename by reading the manifest.yml file generated after you run rake assets:precompile
For example, if a browser is requesting this URL:
http://example.org/assets/application.js
They will get redirected to:
http://example.org/assets/application-faa42cf2fd5db7e7290baa07109bc82b.js
This middleware is designed to run on your staging or production environment, where you already precompile all your assets, turn on your asset digest, and turn of asset compilation. This is useful if you’re having a static page or E-Mail which refers to static assets in the asset pipeline, which might be impossible and impractical for you to use an URL with a digest in it.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, sprockets_environment, options = {}) ⇒ Redirect
constructor
A new instance of Redirect.
Constructor Details
#initialize(app, sprockets_environment, options = {}) ⇒ Redirect
Returns a new instance of Redirect.
35 36 37 38 39 40 |
# File 'lib/sprockets/redirect.rb', line 35 def initialize(app, sprockets_environment, = {}) @app = app @prefix = [:prefix] || "/assets" @asset_host = [:asset_host] @environment = sprockets_environment end |
Instance Method Details
#call(env) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/sprockets/redirect.rb', line 42 def call(env) @request = Rack::Request.new(env) if should_redirect? redirect_to_digest_version(env) else @app.call(env) end end |