我在rails 3.2.2应用程序上使用1.2.2的高电压,似乎不能让我的应用程序在找不到页面时触发自定义的404 -我只是得到了"Routing Error,No the:“错误页面。
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中设置了以下内容(我相信这是启动路由错误的Rails3.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但它仍然不起作用。
我被难住了!有人能帮上忙吗?
发布于 2013-12-07 09:46:16
我能够得到一个自定义的404页与高压工作与以下修改:
注意:如果是在本地测试,则需要运行RAILS_ENV=production rails s,因为开发模式会显示不同的404错误页面。
# config/application.rb
config.exceptions_app = self.routes
# config/routes.rb
get '/404', to: 'errors#not_found'然后我们只需要为errors/not_found.html.erb创建一个ErrorsController和一个视图
https://stackoverflow.com/questions/15422040
复制相似问题