From 4db4661a67529d6238ed255cd51d42d6f68306e1 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 10 Oct 2007 02:34:42 +0000 Subject: rescue_from accepts :with => lambda { |exception| ... } or a normal block. Closes #9827. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7822 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/rescue.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/rescue.rb b/actionpack/lib/action_controller/rescue.rb index 4dbb3aca85..fa847a8274 100644 --- a/actionpack/lib/action_controller/rescue.rb +++ b/actionpack/lib/action_controller/rescue.rb @@ -71,10 +71,10 @@ module ActionController #:nodoc: # exception.record.new_record? ? ... # end # end - def rescue_from(*klasses) + def rescue_from(*klasses, &block) options = klasses.extract_options! - unless options.has_key?(:with) # allow nil - raise ArgumentError, "Need a handler. Supply an options hash that has a :with key as the last argument." + unless options.has_key?(:with) + block_given? ? options[:with] = block : raise(ArgumentError, "Need a handler. Supply an options hash that has a :with key as the last argument.") end klasses.each do |klass| @@ -192,8 +192,11 @@ module ActionController #:nodoc: end def handler_for_rescue(exception) - if handler = rescue_handlers[exception.class.name] + case handler = rescue_handlers[exception.class.name] + when Symbol method(handler) + when Proc + handler.bind(self) end end -- cgit v1.2.3