Openhood

Openhood Experiments

Let's share our tech experiments and discoveries.
By Openhood
rails rails 3 Estimated reading time:

Add routes at runtime on Rails 3

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:

Read more

Read more: Add routes at runtime on Rails 3