diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index 5b8f801b73617..87fb8670ac2e4 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -70,10 +70,12 @@ def asset_path(source, default_ext = nil, body = false, protocol = nil) private def debug_assets? - Rails.env.development? || Rails.env.test? || - params[:debug_assets] == '1' || params[:debug_assets] == 'true' - rescue NoMethodError - false + begin + params[:debug_assets] == '1' || + params[:debug_assets] == 'true' + rescue NoMethodError + false + end || Rails.application.config.assets.debug end # Override to specify an alternative prefix for asset path generation. diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index 4d47c69d0cb07..3bc8a482995a0 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -144,8 +144,6 @@ def url_for(*args) end test "javascript include tag" do - Rails.env.stubs(:test?).returns(false) - assert_match %r{}, javascript_include_tag(:application) @@ -159,14 +157,12 @@ def url_for(*args) assert_match %r{\n}, javascript_include_tag("xmlhr", "extra") - Rails.env.stubs(:test?).returns(true) + assert_match %r{\n}, + javascript_include_tag(:application, :debug => true) + @config.assets.debug = true assert_match %r{\n}, javascript_include_tag(:application) - - assert_match %r{}, - javascript_include_tag(:application, :debug => false) - end test "stylesheet path" do @@ -183,8 +179,6 @@ def url_for(*args) end test "stylesheet link tag" do - Rails.env.stubs(:test?).returns(false) - assert_match %r{}, stylesheet_link_tag(:application) @@ -203,14 +197,12 @@ def url_for(*args) assert_match %r{\n}, stylesheet_link_tag("style", "extra") - Rails.env.stubs(:test?).returns(true) + assert_match %r{\n}, + stylesheet_link_tag(:application, :debug => true) + @config.assets.debug = true assert_match %r{\n}, stylesheet_link_tag(:application) - - assert_match %r{}, - stylesheet_link_tag(:application, :debug => false) - end test "alternate asset prefix" do diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 0c33c87dd82a0..ae45a174fd23d 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -226,7 +226,7 @@ If any of the files in the manifest have changed between requests, the server re h4. Debugging Assets -You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL and Sprockets expands the lines which load the assets. For example, if you had an +app/assets/javascripts/application.js+ file containing these lines: +You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL or set +config.assets.debug+ and Sprockets expands the lines which load the assets. For example, if you had an +app/assets/javascripts/application.js+ file containing these lines: //= require "projects" diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index cd850b6a756e8..f1add6889085c 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -38,6 +38,7 @@ def initialize(*) @assets.precompile = [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ] @assets.prefix = "/assets" @assets.version = '' + @assets.debug = false @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] @assets.js_compressor = nil diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index dcf4ace264438..4ab940c66bae8 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -24,4 +24,7 @@ # Do not compress assets config.assets.compress = false + + # Expands the lines which load the assets + config.assets.debug = true end