How do I emulate directory structure with routes?

I’ve got something that I’m not sure is actually doable. I have a
very complex model relationship with a lot of parent/child/grandchild/
greatgrandchild etc stuff going on. Is there a way to do a route like
this?

projects/:project_name/:sequence_acronym/:shot_number/:department/:eleme
nt_name/:version/

where:

project is the parent of sequence
sequence is the parent of shot
shot and department are parents to element
element (will) exists in an acts_as_versioned model.

or to also show it

tld.com/projects/:project_name/:department/:element_name/:version/

Which would show a specific version of an element.

I’m also interested in stepping this down as emulated directory
structure.

tld.com/projects/:project_name/
tld.com/projects/:project_name/:sequence_acronym/
tld.com/projects/:project_name/:sequence_acronym/:shot_number/

etc.

Is this kind of stuff doable? Is this acts_as_tree (which i’ve seen
in the book but never in a live implementation)

John A.
[email protected]

Meticulous | www.meticulous.com (work)
Rotoscope | www.rotoscope.com (sound: rock band)
Boboroshi & Kynz | www.boboroshiandkynz.com (sound: electronic)
Personal Weblog | www.boboroshi.com (play)

“Those who would give up essential Liberty, to purchase a little
temporary Safety, deserve neither Liberty nor Safety.”
- Benjamin Franklin (1706-1790)
Reply of the Pennsylvania Assembly to the
Governor
November 11, 1755

Hi !

2006/2/12, John A. [email protected]:

tld.com/projects/:project_name/:sequence_acronym/:shot_number/:department/:element_name/:version/

where:

project is the parent of sequence
sequence is the parent of shot
shot and department are parents to element
element (will) exists in an acts_as_versioned model.

No problem. Simply implement the right action, and you’ll be fine. I
do something similar in a product catalog application. My routes are:

map.product_details ‘products/details/:product_no’, :controller =>
‘admin/product_catalog/products’, :action => ‘public_view’,
:product_no => /^[-\w."'%]+$/
map.product_list ‘products/*category_path’, :controller =>
‘admin/product_catalog/products’, :action => ‘public_index’

Is this kind of stuff doable? Is this acts_as_tree (which i’ve seen in the
book but never in a live implementation)

acts_as_tree makes an ActiveRecord model behave as if it were a tree.
It has nothing to do with routes.

If you need more help, don’t hesitate to ask !

Bye !

I don’t understand how that directly relates to setting up a route
where almost every value is a variable…

so projects/whitetiger/ would pull the projects/show/2
projects/whitetiger/opn/ would pull the opening sequence in white
tiger (sequence is a model where acronym is unique within scope of
project_id or the parent)

and so on and so forth.

On Feb 12, 2006, at 12:21 PM, Francois B. wrote:

project is the parent of sequence
map.product_list ‘products/*category_path’, :controller =>
‘admin/product_catalog/products’, :action => ‘public_index’

John A.
[email protected]

Meticulous | www.meticulous.com (work)
Rotoscope | www.rotoscope.com (sound: rock band)
Boboroshi & Kynz | www.boboroshiandkynz.com (sound: electronic)
Personal Weblog | www.boboroshi.com (play)

“Those who would give up essential Liberty, to purchase a little
temporary Safety, deserve neither Liberty nor Safety.”
- Benjamin Franklin (1706-1790)
Reply of the Pennsylvania Assembly to the
Governor
November 11, 1755

AH!!! Okay. I wasn’t quite understanding the controller aspects of
how to make it work. Thank you :slight_smile: Off to play…

On Feb 12, 2006, at 8:42 PM, Francois B. wrote:

:controller => ‘elements’, :action => ‘view’, :version => nil,
@element = @dept.elements.find_by_name(params[:element_name]
So,

Bye !

François Beausoleil
http://blog.teksol.info/


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

John A.
[email protected]

Meticulous | www.meticulous.com (work)
Rotoscope | www.rotoscope.com (sound: rock band)
Boboroshi & Kynz | www.boboroshiandkynz.com (sound: electronic)
Personal Weblog | www.boboroshi.com (play)

“Those who would give up essential Liberty, to purchase a little
temporary Safety, deserve neither Liberty nor Safety.”
- Benjamin Franklin (1706-1790)
Reply of the Pennsylvania Assembly to the
Governor
November 11, 1755

Hi !

2006/2/12, John A. [email protected]:

I don’t understand how that directly relates to setting up a route where
almost every value is a variable…

Let’s take one of your routes as an example:
map.connect ‘projects/:project_name/:department/:element_name/:version’,
:controller => ‘elements’, :action => ‘view’, :version => nil,
:requirements => {:version => /^\d+$/}

This tells Rails to match any URLs from the form above, and call #view
in ElementsController. Here’s a possible implementation of said
method:

class ElementsController < ApplicationController
def view
@project = Project.find_by_project_name(params[:project_name]
@dept = @project.departments.find_by_name(params[:department]
@element = @dept.elements.find_by_name(params[:element_name]
if params[:version] then
@element = @element.find_version(params[:version])
end
end
end

Notice in the route I put :version => nil, :requirements => {:version
=> /^\d+$/} ? That tells Rails tht the version parameter is optional,
but if it is present, it must match the given regular expression.

So,

http://localhost/projects/zoomer/finance/budget

will retrieve the latest version of the budget, while

http://localhost/projects/zoomer/finance/budget/4

will retrieve version 4 of the budget.

Ask away if you need more info !

Bye !