1

我如何在生产模式下呈现我的错误页面,以便它们与其余页面的布局相同?例如,不是 404 作为标准

<h1>The page you were looking for doesn't exist.</h1>
    <p>You may have mistyped the address or the page may have moved.</p>

没有任何布局,但我的布局中的这条消息(称为application.html.haml)?

这是真的吗?我需要写什么以及在哪里写?我用谷歌搜索,但对于自己的布局没有找到好的布局......

我使用 rails 3.2.8,ruby 1.9.3

4

2 回答 2

4

一种解决方案是:

# In config/application.rb
config.exceptions_app = self.routes

# In routes
match "/404", to: "errors#not_found"
match "/500", to: "errors#server_error"

# app/controllers/errors_controller.rb

class ErrorsController < ApplicationController
  # Inherits layout from ApplicationController 

  def not_found
  end

  def server_error
  end
end

# app/views/errors/not_found.haml
%h1 Didn't find nothing!

# app/views/errors/server_error.haml
%h1 FUBAR!
于 2013-03-06T15:01:40.090 回答
0

我使用这种方法,你应该在 Rails 3 中找到相同的方法

http://henrik.nyh.se/2008/07/rails-404/

于 2013-03-06T13:21:15.853 回答