# I can't work out how to set up my routes

**URL:** <https://www.ruby-forum.com/t/i-cant-work-out-how-to-set-up-my-routes/73213>\
**Category:** Rails\
**Created:** [October 23, 2006, 12:17am UTC](https://www.ruby-forum.com/t/i-cant-work-out-how-to-set-up-my-routes/73213 "2006-10-23T00:17:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicksnels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicksnels](https://www.ruby-forum.com/u/nicksnels)\
**Post date:** [October 23, 2006, 12:17am UTC](https://www.ruby-forum.com/t/i-cant-work-out-how-to-set-up-my-routes/73213/1 "2006-10-23T00:17:22Z")

</div>

Hello. This is my first post to the forum so I’ll give a little  
introduction. I am currently at university in guildford, uk. I’m  
learning ruby on rails on the side of my course and currently building  
an application to display events, blog posts, and various info for a  
diversity training organisation.

My problem is in using the routes.

What I want is to have is:

for the normal user viewing the website, they should visit:

domainname/:team\_name/:action/:id

the organisation has seperate teams and the info on the screen needs to  
be for one team at a time, the first page will have a team selection  
page.

it will search for the :team\_name in the database and filter all  
subsequent information for this team.

All of the public site viewing goes through the same controller  
(:siteview).

There is then an admin side which is made up of lots of different  
controllers (one for each type of data) and I would like the url to be  
of the form:

domainname/admin/:controller/:action/:id

I’m going round in circles with it now. At the moment I can only get  
either the public site OR the admin site to work at once:

for the admin:  
map.connect ‘admin/:controller/:action/:id’

but then the link\_to bits in the public pages make links including the  
full controller in the page.

for the public site:  
map.connect ‘:team\_name/:action/:id’

but then now the admin pages get processed through the public site  
controller.

I have tried convoluted ways to make the public site controller to  
recognise the ‘admin’ special word and redirect to admin pages but that  
doesn’t resolve link\_to issues and seems overly complicated.

I am sure there is a far neater solution and I am willing to change the  
structure of my urls if it makes it easier (I could change my controller  
structure too but that would involve more work and so I would prefer not  
to).

Thanks for any help you can offer me.

Nick

---

<div class="post-metadata">

**Author:** ![nicksnels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicksnels](https://www.ruby-forum.com/u/nicksnels)\
**Post date:** [October 23, 2006, 10:19am UTC](https://www.ruby-forum.com/t/i-cant-work-out-how-to-set-up-my-routes/73213/2 "2006-10-23T10:19:45Z")

</div>

Try this:

map.connect ‘admin/:controller/:action/:id’

map.connect ‘:team\_name/:action/:id’, :controller =\> “siteview”

1. The Route for the admin part has to be before the other map in the  
routes file, otherwise the other route would match also for /admin/…  
and look for a team called “admin” (btw: you should prevent creation of  
a team called “admin” as that would never be able tothe public  
views…)

2. you have to specify the controller for the :team\_name route …

Hope that helps, maybe you could give more info if not…

---

<div class="post-metadata">

**Author:** ![nicksnels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicksnels](https://www.ruby-forum.com/u/nicksnels)\
**Post date:** [October 23, 2006, 3:18pm UTC](https://www.ruby-forum.com/t/i-cant-work-out-how-to-set-up-my-routes/73213/3 "2006-10-23T15:18:26Z")

</div>

Thorsten L wrote:

> Try this:
> 
> map.connect ‘admin/:controller/:action/:id’
> 
> map.connect ‘:team\_name/:action/:id’, :controller =\> “siteview”

the problem with this is that when I used a link\_to tag in the siteview  
area the link that is made uses the first route, eg.  
domainname/admin/siteview/course/3 instead of  
domainname/someteam/course/3

ta

---

<div class="post-metadata">

**Author:** ![nicksnels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicksnels](https://www.ruby-forum.com/u/nicksnels)\
**Post date:** [October 24, 2006, 9:16pm UTC](https://www.ruby-forum.com/t/i-cant-work-out-how-to-set-up-my-routes/73213/4 "2006-10-24T21:16:31Z")

</div>

Thorsten L wrote:

> stupid me, you’re right… well you would have to setup individual  
> routes for each admin controller:
> 
> map.connect ‘admin/users/:action/:id’, :controller =\> ‘users’  
> map.connect ‘admin/teams/:action/:id’, :controller =\> ‘teams’  
> etc. pp.
> 
> don’t see any other solution, but i’m no pro either 😃

its inelegant but it will work and its more important for me to get the  
site working than have perfect elegance. cheers!

---

<div class="post-metadata">

**Author:** ![nicksnels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicksnels](https://www.ruby-forum.com/u/nicksnels)\
**Post date:** [October 23, 2006, 3:32pm UTC](https://www.ruby-forum.com/t/i-cant-work-out-how-to-set-up-my-routes/73213/5 "2006-10-23T15:32:42Z")

</div>

stupid me, you’re right… well you would have to setup individual  
routes for each admin controller:

map.connect ‘admin/users/:action/:id’, :controller =\> ‘users’  
map.connect ‘admin/teams/:action/:id’, :controller =\> ‘teams’  
etc. pp.

don’t see any other solution, but i’m no pro either 😃
