Topic: Question about Routes...

I'm just getting to grips with the more usual RoR methods but haven't really touched on routes before now. However I'm now trying to write an application (it might end up as several to be honest) that will deal with a series of projects which are configurable by the administrator of the application. I'll give a couple of scenarios that I'd like to see on the URL's and go from there. All the names here are examples :-)

Say I've got three projects - apples, bananas, cherries. I'd like to be able to access these by the following format.

www.domain.com/apples
www.domain.com/bananas
www.domain.com/cherries

I'm pretty sure I can setup the routes.rb (with my current level of knowledge) to forward these requests to www.domain.com/projects/apples etc.

Each of these projects could have there own sub-projects within them as well:

www.domain.com/apples/wiki
www.domain.com/bananas/defects
www.domain.com/cherries/tasks

This is where I come a little unstuck with the routes process. Take the "defects" sub-project. Ideally I'd like the following URL:
www.domain.com/bananas/defects/show/1

to forward the user on to show the first defect in the project bananas. However I'm not sure how to configure the routes file so that both the project and the defect number come through as parameters without messing up the rest of the routes in the file (take a default routes file as a starting position).

I'm also a little unsure if my approach here is the best one to take. There's also the problem of administering the projects so www.domain.com/apples/admin/ should take you to the administration page for the project. Should I use an "admin" folder then put the controller/action on after? How would this affect the setup of the routes.rb file?

Feel free to ask me questions on this - I'm kind of thinking out loud at the moment and I may not have explained this in the best fashion!

George

Re: Question about Routes...

have you considered turning it into a subdomain? So it would be:

apple.domain.com/wiki
bananas.domain.com/defects
cherries.domain.com/tasks

See this wiki article for how to do this (although it's for account keys, it's very similar).

If you don't want to do that, you can still accomplish this with routes:

# bottom of routes.rb
map.connect "/:project/:controller/:action/:id"

Then it should pass params[:project] to the controller action when specifying a project.

Railscasts - Free Ruby on Rails Screencasts

Re: Question about Routes...

Having read a couple of the other posts by folks like BraveDave I was thinking about going down the sub-domain route. I'll take a read of that Wiki article - at the end of the day this decision might be best put forward to the users to see which they'd prefer. It it *their* app after all :-)

In fact I've just noticed this post from this forum about the Locations plugins.

Thanks for the response - I'll let you know how I go :-)