Sometimes you just want to take the forbidden path. We had the case quite recently, while testing a Paypal integration. We did want to add a route to a fake Paypal service with a link back to our website after succesful payment, but at the same time we didn’t want to polute our routes.rb just for test purpose. Hopefully, it’s still possible to add routes at runtime even on Rails 3. The issue is calling Rails::Application.routes.draw clears all existing routes and after that no further route can be defined. The solution is inspired by how Rails is doing route reloading:

begin_routes=Rails::Application.routes_routes.disable_clear_and_finalize=true_routes.clear!Rails::Application.routes_reloader.paths.each{|path|load(path)}_routes.drawdo# here you can add any route you wantget"/test#{rand(1000000)}",:to=>"sessions#new"endActiveSupport.on_load(:action_controller){_routes.finalize!}ensure_routes.disable_clear_and_finalize=falseend

Please note that using Rails::Application is deprecated and that you should replace it with MyApplicationName::Application everywhere instead. Happy hacking ;)

This problem comes when trying to send any UTF-8 character in params. It may even happen without you trying to send any now the rails does automatically add a snowman in all your forms (not a joke). One solution to silence these warnings is to add:

$VERBOSE=nil

somewhere in your initialization. Another solution is to patch rack itself.

I propose an even better solution, the great escape_utils gem. Not only does it removes the warning, escaping will also be faster, I mean like 45x faster!

It’s nearly too easy to be true, just add this to your Gemfile:

gem"escape_utils"

Then somewhere in your initialization (like in config/initializer in your using rails):

moduleRackmoduleUtilsdefescape(s)EscapeUtils.escape_url(s)endendend

Problem solved! Now that you’re at it, why not add these lines too:

require"escape_utils/html/rack"require"escape_utils/html/haml"

If you’re using erb instead of haml, replace last line by:

require"escape_utils/html/erb"

Now all your html escaping will be faster too, this couldn’t be easier!