【问题标题】:How to change the Rails error message text "We're sorry, but something went wrong."如何更改 Rails 错误消息文本“我们很抱歉,但出了点问题。”
【发布时间】:2016-02-11 16:33:05
【问题描述】:

谁能告诉我如何更改 Ruby on Rails 错误消息“我们很抱歉,但出了点问题。”我只是想更改此错误的文本,但由于某种原因,无法确定此页面/文本的位置,以便我可以对其进行修改。

提前感谢您的宝贵时间。

耐多药

【问题讨论】:

    标签: ruby ruby-on-rails-4 error-handling


    【解决方案1】:

    代码位于public/500.html。您可以根据需要进行更改。

    #public/500.html
    <!DOCTYPE html>
    <html>
    <head>
      <title>We're sorry, but something went wrong (500)</title>
      <meta name="viewport" content="width=device-width,initial-scale=1">
      <style>
      body {
        background-color: #EFEFEF;
        color: #2E2F30;
        text-align: center;
        font-family: arial, sans-serif;
        margin: 0;
      }
    
      div.dialog {
        width: 95%;
        max-width: 33em;
        margin: 4em auto 0;
      }
    
      div.dialog > div {
        border: 1px solid #CCC;
        border-right-color: #999;
        border-left-color: #999;
        border-bottom-color: #BBB;
        border-top: #B00100 solid 4px;
        border-top-left-radius: 9px;
        border-top-right-radius: 9px;
        background-color: white;
        padding: 7px 12% 0;
        box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
      }
    
      h1 {
        font-size: 100%;
        color: #730E15;
        line-height: 1.5em;
      }
    
      div.dialog > p {
        margin: 0 0 1em;
        padding: 1em;
        background-color: #F7F7F7;
        border: 1px solid #CCC;
        border-right-color: #999;
        border-left-color: #999;
        border-bottom-color: #999;
        border-bottom-left-radius: 4px;
        border-bottom-right-radius: 4px;
        border-top-color: #DADADA;
        color: #666;
        box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
      }
      </style>
    </head>
    
    <body>
      <!-- This file lives in public/500.html -->
      <div class="dialog">
        <div>
          <h1>We're sorry, but something went wrong.</h1>
        </div>
        <p>If you are the application owner check the logs for more information.</p>
      </div>
    </body>
    </html>
    

    您可以使用自己的动态错误页面自定义错误消息。看看这个tutorial 如何实现它。

    【讨论】:

    • 天啊,我看错目录了!感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    • 2012-07-29
    • 2012-04-19
    • 2012-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多