REST Rails 2 nested routes without resource names?

Posted by mrbrdo on Stack Overflow See other posts from Stack Overflow or by mrbrdo
Published on 2010-06-11T18:06:20Z Indexed on 2010/06/11 18:23 UTC
Read the original article Hit count: 168

Filed under:

I'm using Rails 2. I have resources nested like this: - university_categories - universities - studies - professors - comments

I wish to use RESTful routes, but I don't want all that clutter in my URL. For example instead of: /universities/:university_id/studies/:study_id/professors/:professor_id I want: /professors/:university_id/:study_id/:professor_id (I don't map professors seperately so there shouldn't be a confusion between this and /professors/:professor_id since that route shouldn't exist). Again, I want to use RESTful resources/routes... Also note, I am using slugs instead of IDs. Slugs for studies are NOT unique, while other are. Also, there are no many-to-many relationships (so if I know the slug of a professor, which is unique, I also know which study and university and category it belongs to, however I still wish this information to be in the URI if possible for SEO, and also it is necessary when adding a new professor). I do however want to use shallow nesting for "administrator" URIs like edit, destroy (note the problem here with Study since it's slug is not unique, though)...

I would also like some tips on how to use the url helpers so that I don't have too much to fix if I change the routes in the future...

Thank you.

© Stack Overflow or respective owner

Related posts about ruby-on-rails