aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-10-10 02:34:42 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-10-10 02:34:42 +0000
commit4db4661a67529d6238ed255cd51d42d6f68306e1 (patch)
treef6cad1f3cdb80663140ab22bcae7db734e9f1e4a /actionpack/lib
parent4aabe46341dd6db9bf9bbbbc27c32f467a7c55b7 (diff)
downloadrails-4db4661a67529d6238ed255cd51d42d6f68306e1.tar.gz
rails-4db4661a67529d6238ed255cd51d42d6f68306e1.tar.bz2
rails-4db4661a67529d6238ed255cd51d42d6f68306e1.zip
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
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/rescue.rb11
1 files changed, 7 insertions, 4 deletions
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