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?
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.
“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
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:
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’
“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
“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
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.