Hello, I am new to Rails, so please excuse me if I might ask something really obvious: I''d like to create a web app with pretty URLs that mimics the behavior of an online directory, just like a FTP server for example: /Folder 1/Folder 2/Folder 3/Object 1 Let''s say all the elements referenced on the path are instances of the same class in the database, and each of them has_many of themselves. The hierarchy can theoretically be infinitelly long. So as far as I can see I can''t solve this with a routing. Is ths possible at all to do in Rails? Juerg
This helped me with something similar: http://blog.chanezon.com/articles/2005/05/20/rails-tip-create-a-route-with-an-arbitrary-number-of-parameters But the problem I''m still having is that with my setup I might have a path like this: articles/category1/category2/category3/article-title (should display the article) or like this: articles/category1/category2 (should display a list of articles and categories in category2) And I have no clean way of determining whether I should be setting up the Category model/controller or the Article model/controller. Currently I''m passing everything to one method of the article controller that does (way too many) queries to figure it all out, then call other actions in the controller afterwards. Yuck... Justin On 11/7/05, Jürg Lehni <juerg-g1/QdencEOjHJcxqWAjuhg@public.gmane.org> wrote:> Hello, > > I am new to Rails, so please excuse me if I might ask something really obvious: > > I''d like to create a web app with pretty URLs that mimics the behavior > of an online directory, just like a FTP server for example: > > /Folder 1/Folder 2/Folder 3/Object 1 > > Let''s say all the elements referenced on the path are instances of the > same class in the database, and each of them has_many of themselves. > > The hierarchy can theoretically be infinitelly long. > > So as far as I can see I can''t solve this with a routing. > > Is ths possible at all to do in Rails? > > Juerg > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Justin Blake wrote:> But the problem I''m still having is that with my setup I might have a > path like this: > > articles/category1/category2/category3/article-title > (should display the article) > > or like this: > > articles/category1/category2 > (should display a list of articles and categories in category2) > > And I have no clean way of determining whether I should be setting up > the Category model/controller or the Article model/controller.Without thinking to long about it, why not have urls like this: articles/category/category1/category2/category3/title/article-title You can easily split it that way. I would probably prefer to just do articles/category/title where category == the last subcategory, but this of course depends on how you set up your db. Sascha Ebach
On 11/7/05, Sascha Ebach <se-eFwX6J65rk9VioaHkBSlcw02NpfuEekPhC4ANOJQIlc@public.gmane.org> wrote:> I would probably prefer to just do > > articles/category/title > > where category == the last subcategory, but this of course depends on how > you set up your db.I would LOVE to do it that way. The problem is I''m trying to match a legacy url scheme. I guess I am just stuck with my ugly method for now. Thanks, Justin
Justin Blake wrote:> I would LOVE to do it that way. The problem is I''m trying to match a > legacy url scheme. I guess I am just stuck with my ugly method for > now.In that case the cleanest method might be to just test if the last part of the url is a title or a category and when both apply than somehow resolve it. Sascha