diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-13 23:28:10 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-13 23:28:10 +0000 |
commit | aaf6956c4776d6c43f77ab540cb51becdac3e00e (patch) | |
tree | 71fa256ec7e53ef6e04cdaf95b582569f13f716b | |
parent | 2c5a2e7f2e45207a204cf97a99445b2c2823e5e6 (diff) | |
download | rails-aaf6956c4776d6c43f77ab540cb51becdac3e00e.tar.gz rails-aaf6956c4776d6c43f77ab540cb51becdac3e00e.tar.bz2 rails-aaf6956c4776d6c43f77ab540cb51becdac3e00e.zip |
Added TemplateError#backtrace that makes it much easier to debug template errors from unit and functional tests
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@145 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/template_error.rb | 13 |
2 files changed, 12 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index a8fa53a143..54d451ad71 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added TemplateError#backtrace that makes it much easier to debug template errors from unit and functional tests + * Added display of error messages with scaffolded form pages * Added option to ERB templates to swallow newlines by using <% if something -%> instead of just <% if something %>. Example: diff --git a/actionpack/lib/action_view/template_error.rb b/actionpack/lib/action_view/template_error.rb index ab05b3303f..0ac8ee4c37 100644 --- a/actionpack/lib/action_view/template_error.rb +++ b/actionpack/lib/action_view/template_error.rb @@ -28,7 +28,7 @@ module ActionView end end - def source_extract + def source_extract(indention = 0) source_code = IO.readlines(@file_name) start_on_line = [ line_number - SOURCE_CODE_RADIUS - 1, 0 ].max @@ -37,9 +37,9 @@ module ActionView line_counter = start_on_line extract = source_code[start_on_line..end_on_line].collect do |line| line_counter += 1 - "#{line_counter}: " + line + "#{' ' * indention}#{line_counter}: " + line end - + extract.join end @@ -71,6 +71,13 @@ module ActionView "\n\n" end + def backtrace + [ + "On line ##{line_number} of #{file_name}\n\n#{source_extract(4)}\n " + + clean_backtrace(original_exception).join("\n ") + ] + end + private def strip_base_path(file_name) file_name.gsub(@base_path, "") |