参考链接:https://github.com/mirego/gaffe
step1. gem ‘gaffe’
step2. bundle install
step3. 在 config/initializers/gaffe.rb
中写入
|
|
step4. 创建ErrorsController
|
|
step5. 创建自己的(也可以用它默认的),目录为views/errors/not_found.erb
这种。如下图是这个gem的文件,我们可以覆盖:
step6. 修改config/environments/development.rb
,可以看到报错的页面都会给特定的页面,比如404.erb等,但是在开发或者测试环境还是不要设置,因为错误信息看不到,我们自己不好看错误。(Rails prefers to render its own debug-friendly errors in the development environment, which is totally understandable. However, if you want to test Gaffe’s behavior in development you’ll have to edit the config/environments/development.rb file.)
测试环境可以这样干:config/environments/test.rb