# How to route /app/name to /name?

**URL:** <https://www.ruby-forum.com/t/how-to-route-app-name-to-name/90677>\
**Category:** Rails\
**Created:** [March 30, 2007, 10:35pm UTC](https://www.ruby-forum.com/t/how-to-route-app-name-to-name/90677 "2007-03-30T22:35:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sneptune](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sneptune](https://www.ruby-forum.com/u/sneptune)\
**Post date:** [March 30, 2007, 10:35pm UTC](https://www.ruby-forum.com/t/how-to-route-app-name-to-name/90677/1 "2007-03-30T22:35:09Z")

</div>

Hi,

From the rail recipe book, I found that it is possible to set up route  
rule so that the url can parsed and map differently. However, what I am  
trying to accomplish is that if /abc is typed and the controller abc  
does not exists, it will try to look into /app (i.e. app/abc). Is this  
possible?

---

<div class="post-metadata">

**Author:** ![sneptune](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sneptune](https://www.ruby-forum.com/u/sneptune)\
**Post date:** [March 30, 2007, 10:40pm UTC](https://www.ruby-forum.com/t/how-to-route-app-name-to-name/90677/2 "2007-03-30T22:40:55Z")

</div>

map.connect “:name”, :controller =\> “app”  
where name is a GET parameter feed into the url on a link\_to (or you  
can type your domain\_name/\<whatever\_name\> to access the page  
directly).

On Mar 30, 1:35 pm, Wai T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![sneptune](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sneptune](https://www.ruby-forum.com/u/sneptune)\
**Post date:** [March 30, 2007, 10:45pm UTC](https://www.ruby-forum.com/t/how-to-route-app-name-to-name/90677/3 "2007-03-30T22:45:54Z")

</div>

wilson wrote:

> map.connect “:name”, :controller =\> “app”  
> where name is a GET parameter feed into the url on a link\_to (or you  
> can type your domain\_name/\<whatever\_name\> to access the page  
> directly).
> 
> On Mar 30, 1:35 pm, Wai T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Thanks for the quick reply, but that route will only get to the app  
controller with params[:name] = ‘abc’. I would like to go to the abc  
method instead of the index method, is it possible?

---

<div class="post-metadata">

**Author:** ![sneptune](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sneptune](https://www.ruby-forum.com/u/sneptune)\
**Post date:** [March 30, 2007, 11:53pm UTC](https://www.ruby-forum.com/t/how-to-route-app-name-to-name/90677/4 "2007-03-30T23:53:04Z")

</div>

Hi Wai,

I use this exact route in my app for user homepages:

map.connect ‘:id’, :controller =\> ‘user’, :action =\> ‘user\_home’

this will make [http://foo.com/joe](http://foo.com/joe) map to that controller and action  
and pass the username joe to it  
There might be a better way even as I believe I’m perverting the use  
of :id in this case

-Michael  
[http://javathehutt.blogspot.com](http://javathehutt.blogspot.com)

---

<div class="post-metadata">

**Author:** ![sneptune](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sneptune](https://www.ruby-forum.com/u/sneptune)\
**Post date:** [March 31, 2007, 1:45am UTC](https://www.ruby-forum.com/t/how-to-route-app-name-to-name/90677/5 "2007-03-31T01:45:23Z")

</div>

Ff I’m reading it correctly, you want to get to the action ‘abc’ with  
a controller of ‘app’?

map.connect “abc”, :controller =\> “app”, :action =\> “abc”

This only requires the controller and the action when you create a  
link\_to.  
As for the url, “domain\_name/abc” should work.

On Mar 30, 1:45 pm, Wai T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![sneptune](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sneptune](https://www.ruby-forum.com/u/sneptune)\
**Post date:** [March 31, 2007, 2:13am UTC](https://www.ruby-forum.com/t/how-to-route-app-name-to-name/90677/6 "2007-03-31T02:13:25Z")

</div>

On Mar 30, 3:35 pm, Wai T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,
> 
> From the rail recipe book, I found that it is possible to set up route  
> rule so that the url can parsed and map differently. However, what I am  
> trying to accomplish is that if /abc is typed and the controller abc  
> does not exists, it will try to look into /app (i.e. app/abc). Is this  
> possible?

Actually it’s pretty easy. In your routes.rb, try this:

map.connect ‘/:action’, :controller =\> ‘app’

However, the order of your route rules in routes.rb is very  
important! Higher routes take priority. So if you still have the  
default catch-all route that Rails generates for you in your routes.rb  
(the :controller/:action:/:id route) make sure your route is _above_  
it.

Also, you might not need that / that I’ve written. It could be that  
map.connect ‘:action’, :controller =\> ‘app’ is correct.

Whenever I have problems with routes, I comment out all the other  
routes, try the url in the browser again, and then look at the  
development log for an error message - it will tell you what it  
_thought_ it was supposed to do with the url, which is usually enought  
insight to solve the problem.

Jeff

> **[Hey Daddio!](http://softiesonrails.com)**
>
> Home of Hey Daddio Software
