在rails中自定义消息或重定向400错误请求(因为params上的未显示%)

如果我要求,我收到400 Bad Request

http://localhost:3000/cont/act?params=% 

在日志上它只显示

 => Booting Thin => Rails 3.2.14 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [Zonebie] Setting timezone: ZONEBIE_TZ="Tokelau Is." dalton >> Thin web server (v1.5.1 codename Straight Razor) >> Maximum connections set to 1024 >> Listening on 0.0.0.0:3000, CTRL+C to stop !! Invalid request 

如何为此类错误制作自定义消息或重定向?

PS

我尝试在谷歌上使用几个不同的中间件解决方案。

喜欢添加

 class InvalidUriCatch puts "Hello" def initialize(app) @app = app end def call(env) puts "hello" query = Rack::Utils.parse_nested_query(env['QUERY_STRING'].to_s) rescue :bad_query if query == :bad_query [302, {'Location' => 'google.com'}, "a"] else @app.call(env) end end end 

在我的库和放

 config.middleware.insert_before ActionDispatch::Static, "InvalidUriCatch" 

在application.rb上

但是,仍然不起作用

当我请求它时,它甚至没有在rails s log上输出hello。

我的代码不起作用,因为我在开发中使用Thin(我的应用程序使用乘客进行生产)。

这就是为什么在生产中它显示错误与回溯,而在本地它没有。