Created
May 3, 2012 02:05
-
-
Save snikch/2582549 to your computer and use it in GitHub Desktop.
Prevent AssetNotPrecompiledError before it occurs.
This file contains hidden or 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
# Checks that the precompile list contains this file or raises an error, in dev only | |
# Note: You will need to move config.assets.precompile to application.rb from production.rb | |
def javascript_include_tag *sources | |
sources.each do |source| | |
raise "Hey, #{source} is not in the precompile list. This will fall apart in production." unless Rails.application.config.assets.precompile.any? do |matcher| | |
if matcher.is_a? Proc | |
matcher.call(source) | |
elsif matcher.is_a? Regexp | |
matcher.match(source) | |
else | |
matcher.gsub(/\.js/,'') == source.gsub(/\.js/,'') | |
end | |
end | |
end if Rails.env.development? | |
super *sources | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this inside a helper (We have
app/helpers/javascript_helper
).This will prevent
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError
errors in production by checking that the javascript file you're trying to include is in the list of assets to be precompiled.Note: You will need to move any additions to
config.assets.precompile
fromconfig/environments/production.rb
toconfig/application.rb
.