如何在Rails中捕获ActionView :: MissingTemplate错误?
例如,我的PeopleController
有一个Index方法,但它不需要模板。当有人浏览root_url / people时,他们会获得默认的静态错误模板。
这不是唯一有问题的控制器;我希望所有丢失的模板错误将用户重定向到我的自定义视图。
Rails版本 - 3.0.19
提前致谢!
答案 0 :(得分:6)
可能重复:render default template when requested template is missing in Rails
其中说:
在ApplicationController中使用'rescue_from':
class ApplicationController < ActionController::Base
rescue_from ActionView::MissingTemplate do |exception|
# use exception.path to extract the path information
# This does not work for partials
end
end