John Athayde
2006-Feb-12 16:01 UTC
[Rails] 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? tld.com/ 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 Athayde bobo@meticulous.com 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060212/4ba8f57f/attachment.html
Francois Beausoleil
2006-Feb-12 17:21 UTC
[Rails] How do I emulate directory structure with routes?
Hi ! 2006/2/12, John Athayde <bobo@meticulous.com>:> 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 ! -- Fran?ois Beausoleil http://blog.teksol.info/
John Athayde
2006-Feb-12 23:58 UTC
[Rails] How do I emulate directory structure with routes?
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 Beausoleil wrote:> Hi ! > > 2006/2/12, John Athayde <bobo@meticulous.com>: >> tld.com/ >> projects/:project_name/:sequence_acronym/:shot_number/:department/:el >> ement_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'' >-- John Athayde bobo@meticulous.com 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060212/1fd8779b/attachment.html
Francois Beausoleil
2006-Feb-13 01:42 UTC
[Rails] How do I emulate directory structure with routes?
Hi ! 2006/2/12, John Athayde <bobo@meticulous.com>:> 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 ! -- Fran?ois Beausoleil http://blog.teksol.info/
John Athayde
2006-Feb-13 02:04 UTC
[Rails] How do I emulate directory structure with routes?
AH!!!! Okay. I wasn''t quite understanding the controller aspects of how to make it work. Thank you :) Off to play... On Feb 12, 2006, at 8:42 PM, Francois Beausoleil wrote:> Hi ! > > 2006/2/12, John Athayde <bobo@meticulous.com>: >> 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 ! > -- > Fran?ois Beausoleil > http://blog.teksol.info/ > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- John Athayde bobo@meticulous.com 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060213/62b6a86e/attachment-0001.html