dynamically adding and removing routes

Hello,

Is it possible to alter a Rails app's routing table at runtime? I want to be able to add and remove routes from an admin application.

Thanks.

Michael

Michael Allman wrote:

Is it possible to alter a Rails app's routing table at runtime? I want to be able to add and remove routes from an admin application.

I would put p 'yo' inside the route map, run the app, and see how often it prints. I don't know if it's once per route, once per action, or only at startup time.

However, if you need to think outside the route box entirely, I suspect you can use this:

   map.any_route '/*paths', :controller => 'foo', :action => 'any_action'

Now the system will call any_action with a params[:paths] set to an array of each /path/element/ in an URI. Then you parse and dispatch them yourself.

But I can't think of any reason to add or remove routes in a way that solves an actual web problem...

I found that I can just call require 'config/routes' at the right time in my action to rebuild the entire routing table. That's good enough for me.

Thanks.

Michael