# Programmatically add a route

**URL:** <https://www.ruby-forum.com/t/programmatically-add-a-route/171663>\
**Category:** Rails\
**Created:** [July 7, 2009, 11:24am UTC](https://www.ruby-forum.com/t/programmatically-add-a-route/171663 "2009-07-07T11:24:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 7, 2009, 11:24am UTC](https://www.ruby-forum.com/t/programmatically-add-a-route/171663/1 "2009-07-07T11:24:22Z")

</div>

Is there a way to programmartically add a route? I have an outside  
process creating pages that I need to access, but I dont know their  
names or locations until runtime. -Janna B

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 8, 2009, 10:07am UTC](https://www.ruby-forum.com/t/programmatically-add-a-route/171663/2 "2009-07-08T10:07:00Z")

</div>

Janna Brossard wrote:

> Is there a way to programmartically add a route? I have an outside  
> process creating pages that I need to access, but I dont know their  
> names or locations until runtime. -Janna B

Janna,

Sounds messy! Are you sure this is the best option?

What is it you’re trying to achieve?

Gavin

> **[Ruby on Rails tips & Tutorials](https://handyrailstips.com/)**
>
> Ruby on Rails tips and tutorials

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 8, 2009, 2:54pm UTC](https://www.ruby-forum.com/t/programmatically-add-a-route/171663/3 "2009-07-08T14:54:33Z")

</div>

I’m not sure but it seems possible to have a route at the end of your  
routes  
file (with the lowest priority) that would handle any un-handled  
requests.  
You could then dispatch it to wherever you want. Maybe there is a  
better  
way to do it though. Could you give some example URL’s?

On Wed, Jul 8, 2009 at 4:07 AM, Gavin M. \<

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 8, 2009, 2:55pm UTC](https://www.ruby-forum.com/t/programmatically-add-a-route/171663/4 "2009-07-08T14:55:44Z")

</div>

Well, for example. I was going to have it write partials into /public/  
blahblah/\_mypartial!.erb

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 8, 2009, 3:00pm UTC](https://www.ruby-forum.com/t/programmatically-add-a-route/171663/5 "2009-07-08T15:00:40Z")

</div>

Janna Brossard wrote:

> Well, for example. I was going to have it write partials into /public/  
> blahblah/\_mypartial!.erb

map.connect “/blahblah/:partial\_name”, :controller =\> “yourcontroller”,  
:action =\> “your\_action”

This would work provided you’re always routing to the same controller  
and action.

I suppose in the action you’d just call something like

def my\_action  
render :partial =\> params[:partial\_name]  
end

not 100% sure if that would work the way you want it to though.

Can you elaborate a little more?

Gavin

> **[Ruby on Rails tips & Tutorials](https://handyrailstips.com/)**
>
> Ruby on Rails tips and tutorials

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 8, 2009, 9:18pm UTC](https://www.ruby-forum.com/t/programmatically-add-a-route/171663/6 "2009-07-08T21:18:39Z")

</div>

You can add a static file system path to your render call with the :file  
option

2009/7/8, Gavin M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ## [http://handyrailstips.com](http://handyrailstips.com)
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Von meinen Mobilgerät aus gesendet

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 8, 2009, 3:42pm UTC](https://www.ruby-forum.com/t/programmatically-add-a-route/171663/7 "2009-07-08T15:42:51Z")

</div>

Now that I think about it - don’t think this would work

render looks through the view folders for your partial - not sure if  
you’d be able to store them in the public directory

:S

Gavi

> **[Ruby on Rails tips & Tutorials](https://handyrailstips.com/)**
>
> Ruby on Rails tips and tutorials
