Skip to content

Commit a01d441

Browse files
committed
Fix asset prefixes
1 parent 0e3c71a commit a01d441

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

config.ru

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
require ::File.expand_path('../config/environment', __FILE__)
44

55
# Serve the rails app under a prefix. Defaults to '/achrails'
6-
prefix = ENV['RAILS_PREFIX'] || '/achrails'
7-
6+
prefix = ENV['RAILS_RELATIVE_URL_ROOT']
87
map prefix do
98
run Rails.application
109
end

config/boot.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
# See: https://github.com/Casecommons/pg_search/issues/144
77
require 'pg_search'
88

9+
ENV['RAILS_RELATIVE_URL_ROOT'] ||= '/achrails'

config/initializers/path_patch.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Fix asset paths not being prefixed correctly
2+
# From http://stackoverflow.com/questions/7293918/broken-precompiled-assets-in-rails-3-1-when-deploying-to-a-sub-uri
3+
module Sprockets
4+
module Helpers
5+
module RailsHelper
6+
7+
def asset_path(source, options = {})
8+
source = source.logical_path if source.respond_to?(:logical_path)
9+
path = asset_paths.compute_public_path(source, asset_prefix, options.merge(:body => true))
10+
path = options[:body] ? "#{path}?body=1" : path
11+
if !asset_paths.send(:has_request?)
12+
path = ENV['RAILS_RELATIVE_URL_ROOT'] + path if ENV['RAILS_RELATIVE_URL_ROOT']
13+
end
14+
path
15+
end
16+
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)