【发布时间】:2013-12-19 12:22:32
【问题描述】:
我的应用中的简单 index 操作
def index
@reports = CustomReport.all
end
当应用程序准备好时,我被告知添加exceptions,我从其他application 复制它,因为我不知道,
def index
begin
@reports = CustomReport.all
rescue Exception => e
Rails.logger.info "Exception in design_custom_reports controller, index action"
Rails.logger.info e
flash[:notice] = "Sorry, something went wrong. Please inform administration"
redirect_to :controller => :user, :action => :dashboard
end
end
现在看起来很笨拙是不是?
处理RoR中场景的最佳方式?
【问题讨论】:
-
看不懂这个异常处理器的思路,你想干什么?
-
我真的没有道理。您在从数据库请求所有记录时尝试捕获错误?通常应用程序会在遇到此救援之前停止工作
-
这只是一个旁注,但通常接受的风格不是 def...begin...rescue...end,而是 def...rescue...end。
标签: ruby-on-rails ruby exception