基本Rails 404错误页面 [英] Basic Rails 404 Error Page

查看:99
本文介绍了基本Rails 404错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个简单的答案,这荒唐可笑的时间很长,而且似乎必须如此明显和简单,因为没有人拥有简单易用的傻瓜证明教程。

I have been looking for a simple answer to this for a ridiculously long time and it seems like this has to be so plainly obvious and simple because no one has an easy, idiot proof tutorial.

无论如何,我要做的就是只有一个404.html静态页面,该页面会在引发任何错误时加载。理想情况下,这仅应在生产和分阶段进行。

Anyway, all I want to do is to have a single 404.html static page that loads whenever ANY error is thrown. Ideally this should only happen in production and staging.

我觉得这应该是最简单的事情……但我不知道。

I feel like this should be the easiest thing to do... but I can't figure it out.

任何帮助都很感激。

推荐答案

在您的 ApplicationController

unless  ActionController::Base.consider_all_requests_local
  rescue_from Exception, :with => :render_404
end

private

  def render_404
    render :template => 'error_pages/404', :layout => false, :status => :not_found
  end

现在设置了 error_pages / 404.html 然后您去

...或者也许我对Exceptiona谨慎,您应该从RuntimeError中救出来。

...or maybe I'm overcautious with Exception and you should rescue from RuntimeError instead.

这篇关于基本Rails 404错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆