@@ -30,6 +30,14 @@ def initialize(source)
30
30
end
31
31
end
32
32
33
+ class AbsoluteAssetPathError < ArgumentError
34
+ def initialize ( bad_path , good_path , prefix )
35
+ msg = "Asset names passed to helpers should not include the #{ prefix . inspect } prefix. " <<
36
+ "Instead of #{ bad_path . inspect } , use #{ good_path . inspect } "
37
+ super ( msg )
38
+ end
39
+ end
40
+
33
41
include ActionView ::Helpers ::AssetUrlHelper
34
42
include ActionView ::Helpers ::AssetTagHelper
35
43
@@ -169,15 +177,27 @@ def check_dependencies!(dep)
169
177
rescue Sprockets ::FileNotFound
170
178
end
171
179
172
- # Raise errors when source does not exist or is not in the precompiled list
180
+ # Raise errors when source is not in the precompiled list, or
181
+ # incorrectly contains the assets_prefix.
173
182
def check_errors_for ( source , options )
183
+ return unless self . raise_runtime_errors
184
+
174
185
source = source . to_s
175
- return source if !self . raise_runtime_errors || source . blank? || source =~ URI_REGEXP
186
+ return if source . blank? || source =~ URI_REGEXP
187
+
176
188
asset = lookup_asset_for_path ( source , options )
177
189
178
190
if asset && asset_needs_precompile? ( asset . logical_path , asset . pathname . to_s )
179
191
raise AssetFilteredError . new ( asset . logical_path )
180
192
end
193
+
194
+ full_prefix = File . join ( self . assets_prefix || "/" , '' )
195
+ if !asset && source . start_with? ( full_prefix )
196
+ short_path = source [ full_prefix . size , source . size ]
197
+ if lookup_asset_for_path ( short_path , options )
198
+ raise AbsoluteAssetPathError . new ( source , short_path , full_prefix )
199
+ end
200
+ end
181
201
end
182
202
183
203
# Returns true when an asset will not be available after precompile is run
0 commit comments