Rails-如何处理不存在的路由(“没有匹配[GET]的路由”)? [英] Rails - how to handle routes that don't exist ("No route matches [GET]")?

查看:74
本文介绍了Rails-如何处理不存在的路由(“没有匹配[GET]的路由”)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的路线看起来

match 'about' => 'company#about'

当我设置为网址 http://时本地主机:3000 / aboutttt ,我收到错误消息

When I set to the url http://localhost:3000/aboutttt, I get the error message

No route matches [GET] "/aboutttt"

我想给用户更好的反馈。

I want to give the user better feedback than that.

我认为最好的解决方案可能是将应用重定向回去,或者在应用首页上,但是当我遇到上述错误时,路由中是否存在设置默认路由的任何方式?

The best solution by my opinion could be redirect the app back, or on the homepage of the app, but exist in routes any way to set default route, when I get the error above?

推荐答案

在将环境设置为生产的情况下运行您的应用程序,我想您会发现您不会再看到此消息。

Run your app with the environment set to production and I think you'll find you'll no longer see this message. It's a convenience for debugging while you're developing.

在$code> config / environments / production.rb 中有一个设置。或 config / environments / development.rb (我不记得是哪条路)来控制是否将异常呈现为视图。该版本已停产-您可以在公开中获取404.html,可以随意更改。

There's a setting in config/environments/production.rb or config/environments/development.rb (I can't remember which way round) which controls whether exceptions are rendered as views. This is off for production - instead you get the 404.html that's in public, which you can change as you please.

这篇关于Rails-如何处理不存在的路由(“没有匹配[GET]的路由”)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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