【发布时间】:2013-03-14 23:22:38
【问题描述】:
我在 rails 3.2.2 应用程序上使用 1.2.2 高压,并且似乎无法让我的应用程序在找不到页面时触发自定义 404 - 我只是收到“路由错误” , 没有这样的页面:“错误页面。
Routes.rb:
...
match '/signup', to: 'users#new'
root :to => 'high_voltage/pages#show', :id => 'home'
match '/404', :to => 'errors#not_found'
match '/422', :to => 'errors#server_error'
match '/500', :to => 'errors#server_error'
match '/:id' => 'high_voltage/pages#show', :as => :static, :via => :get
我还在 application.rb 中设置了以下内容(我相信这是 Rails 3.2 引发路由错误的方式):
config.exceptions_app = self.routes
但我仍然得到默认的路由错误页面。
我也尝试在我的应用控制器中使用它:
unless config.consider_all_requests_local
rescue_from Exception, :with => :render_500
rescue_from ActiveRecord::RecordNotFound, :with => :render_404
rescue_from ActionController::RoutingError, :with => :render_404
rescue_from ActionController::UnknownController, :with => :render_404
rescue_from ActionController::UnknownAction, :with => :render_404
end
protected
def render_500 exception
logger.error exception.inspect
render :template => "/errors/server_error.html.haml", :status => 500, :layout => 'application'
end
def render_404 exception
logger.error exception.inspect
render :template => "/errors/not_found.html.haml", :status => 404, :layout => 'application'
end
但还是不行。
我被难住了!有人可以帮忙吗?
【问题讨论】:
-
你删除/public中的404.html和500.html文件了吗?
-
在你建议之前我没有,但它仍然是一样的......
标签: ruby-on-rails ruby high-voltage