Created
November 19, 2012 16:14
-
-
Save antonio/4111541 to your computer and use it in GitHub Desktop.
Avoid Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError
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
# This file monkey patches the Rails include helpers to prevent them from | |
# failing with an AssetNotPrecompiled error. This should be fixed in | |
# Rails 4.x and by then we should delete this file | |
module Sprockets | |
module Helpers | |
module RailsHelper | |
alias_method :original_stylesheet_link_tag, :stylesheet_link_tag | |
alias_method :original_javascript_include_tag, :javascript_include_tag | |
alias_method :original_image_path, :image_path | |
alias_method :original_path_to_image, :path_to_image | |
def log_asset_not_found(sources, type = '') | |
sources.each do |source| | |
logger.warn("\n#########################################") | |
logger.warn("Asset not found => #{source} #{type}") | |
logger.warn("#########################################\n") | |
end | |
end | |
def stylesheet_link_tag(*sources) | |
original_stylesheet_link_tag(*sources) | |
rescue Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError | |
log_asset_not_found(sources, 'css') | |
sources.map { |source| | |
tag("link", { "rel" => "stylesheet", "type" => "text/css", "media" => "screen", "href" => "/assets/#{source}.css" }) | |
}.join("\n").html_safe | |
end | |
def javascript_include_tag(*sources) | |
original_javascript_include_tag(*sources) | |
rescue Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError | |
log_asset_not_found(sources, 'js') | |
sources.map { |source| | |
"<script src=\"/assets/#{source}.js\" type=\"text/javascript\"></script>" | |
}.join("\n").html_safe | |
end | |
def image_path(path) | |
original_image_path(path) | |
rescue Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError | |
log_asset_not_found [path] | |
original_image_path("/assets/#{path}") | |
end | |
alias_method :path_to_image, :image_path | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment