Created
January 11, 2012 16:15
-
-
Save jrochkind/1595405 to your computer and use it in GitHub Desktop.
Rails 3.1.3 asset precompile with SubURI fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ./config/initializers/asset_precompile_prefix_fix.rb | |
# | |
# So we can deploy at a SubURI, and precompile assets to respect that with: | |
# RAILS_RELATIVE_URL_ROOT=/foo rake assets:precompile | |
# | |
# See: http://stackoverflow.com/questions/7293918/broken-precompiled-assets-in-rails-3-1-when-deploying-to-a-sub-uri | |
# | |
# Confirmed working in Rails 3.1.3 | |
# Future versions of Rails may make this monkey patch unneccesary. (or break | |
# it without making it unneccesary) | |
# | |
# | |
# We are monkey patching source originally (in 3.1.3) at: | |
# https://github.com/rails/rails/blob/master/actionpack/lib/sprockets/helpers/rails_helper.rb#L54 | |
module Sprockets | |
module Helpers | |
module RailsHelper | |
included do |klass| | |
klass.alias_method_chain :asset_path, :prefix | |
end | |
def asset_path_with_prefix(*args) | |
path = asset_path_without_prefix(*args) | |
if !asset_paths.send(:has_request?) | |
path = ENV['RAILS_RELATIVE_URL_ROOT'] + path if ENV['RAILS_RELATIVE_URL_ROOT'] | |
end | |
return path | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there anything else besides putting this file into the config/initializers directory and invoking asset:precompile with RAILS_RELATIVE_URL_ROOT?
I'm trying to precompile the assets but the paths will still turn out to be in the form of "/assets/.."