Is there a simple way to wrap ruby/rails with begin rescue blocks?
We're implementing the search functionality in our webapp, using ElasticSearch + Tire. Tire uses callbacks on models that we want to index on the ES server. Sometimes these callbacks fail for some reason.
I want to be able to rescue these errors - Is there a simple way of doing that?
Without you providing more detail, what about something like this
class Model < ActiveRecord::Base
after_save :my_callback
def my_callback
begin
# do the thing you want
rescue
# callback failed - raise error or whetever
end
end
end
我将查看http://mrchrisadams.tumblr.com/post/333036266/catching-errors-in-rails-with-rescue-from ,其中讨论了rescue_from
功能以及如何在整个应用程序中使用它。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.