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

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

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…

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

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 :smiley:

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

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 :smiley:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs