# Dynamically adding and removing routes

**URL:** <https://www.ruby-forum.com/t/dynamically-adding-and-removing-routes/149087>\
**Category:** Rails\
**Created:** [September 20, 2008, 5:14am UTC](https://www.ruby-forum.com/t/dynamically-adding-and-removing-routes/149087 "2008-09-20T05:14:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3e96dc/32.png) [@mjand](https://www.ruby-forum.com/u/mjand)\
**Post date:** [September 20, 2008, 5:14am UTC](https://www.ruby-forum.com/t/dynamically-adding-and-removing-routes/149087/1 "2008-09-20T05:14:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mjand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3e96dc/32.png) [@mjand](https://www.ruby-forum.com/u/mjand)\
**Post date:** [September 20, 2008, 7:09am UTC](https://www.ruby-forum.com/t/dynamically-adding-and-removing-routes/149087/2 "2008-09-20T07:09:12Z")

</div>

Michael A. 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…

–  
Phlip

---

<div class="post-metadata">

**Author:** ![mjand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3e96dc/32.png) [@mjand](https://www.ruby-forum.com/u/mjand)\
**Post date:** [September 20, 2008, 9:33pm UTC](https://www.ruby-forum.com/t/dynamically-adding-and-removing-routes/149087/3 "2008-09-20T21:33:32Z")

</div>

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
