diff options
author | Sam Stephenson <sam@37signals.com> | 2006-03-13 02:11:59 +0000 |
---|---|---|
committer | Sam Stephenson <sam@37signals.com> | 2006-03-13 02:11:59 +0000 |
commit | 3589871de82c12123f62c80b4924d2696412065c (patch) | |
tree | 8f420e61f86e6860a63cb9bbcc812962954d359f /actionpack/lib | |
parent | 955583aed4668981ee32dadcdc7e3c35e83d3adf (diff) | |
download | rails-3589871de82c12123f62c80b4924d2696412065c.tar.gz rails-3589871de82c12123f62c80b4924d2696412065c.tar.bz2 rails-3589871de82c12123f62c80b4924d2696412065c.zip |
Added simple alert() notifications for RJS exceptions when config.action_view.debug_rjs = true. Set debug_rjs = true for the default development environment.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3856 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/base.rb | 5 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/prototype_helper.rb | 21 |
2 files changed, 18 insertions, 8 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 95afff0e84..94e7a47232 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -162,6 +162,11 @@ module ActionView #:nodoc: # shortly. @@local_assigns_support_string_keys = true cattr_accessor :local_assigns_support_string_keys + + # Specify whether RJS responses should be wrapped in a try/catch block + # that alert()s the caught exception (and then re-raises it). + @@debug_rjs = false + cattr_accessor :debug_rjs @@template_handlers = {} diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 1f6aa274db..7781612180 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -370,12 +370,12 @@ module ActionView end private - def include_helpers_from_context - @context.extended_by.each do |mod| - extend mod unless mod.name =~ /^ActionView::Helpers/ + def include_helpers_from_context + @context.extended_by.each do |mod| + extend mod unless mod.name =~ /^ActionView::Helpers/ + end + extend GeneratorMethods end - extend GeneratorMethods - end # JavaScriptGenerator generates blocks of JavaScript code that allow you # to change the content and presentation of multiple DOM elements. Use @@ -425,7 +425,12 @@ module ActionView # <script> tag. module GeneratorMethods def to_s #:nodoc: - @lines * $/ + returning javascript = @lines * $/ do + if ActionView::Base.debug_rjs + javascript.replace "try {\n#{javascript}\n} catch (e) " + javascript << "{ alert('RJS error:\\n\\n' + e.toString()); throw e }" + end + end end # Returns a element reference by finding it through +id+ in the DOM. This element can then be @@ -748,7 +753,7 @@ module ActionView class JavaScriptElementProxy < JavaScriptProxy #:nodoc: def initialize(generator, id) @id = id - super(generator, "$('#{id}')") + super(generator, "$(#{id.to_json})") end def replace_html(*options_for_render) @@ -874,7 +879,7 @@ module ActionView class JavaScriptElementCollectionProxy < JavaScriptCollectionProxy #:nodoc:\ def initialize(generator, pattern) - super(generator, "$$('#{pattern}')") + super(generator, "$$(#{pattern.to_json})") end end end |