Hi, I have this scenario. I have the full path of a page stored in the database (column ''path''). I want to be able to have very short urls for retrieving the pages, so i have this route in my map map.connect ''-/:title'', :controller => ''page'', :action => ''view_by_title'', :title => nil so when I go to /-/PageTitle it gets me the page PageTitle. Pages can have additional path prefixes, so I can have categories. For example "/products" or "/articles/ruby/rails". Let''s say I have lots of categories and I have many articles in them. One is "Writing the simplest CMS that could possibly be useful with Ruby on Rails" or short "WTSCMSTCPBUWROR". It would have a path of "/articles/ruby/rails" and the title would be "WTSCMSTCPBUWROR". So the full url to retrieve this article would be: /-/articles/ruby/rails/WTSCMSTCPBUWROR I don''t know how long the path is going to be. The page could lie in root or have several directory levels. As soon as I try to use the above route I get a routing error. So what do I need to do to make this work? I would need something like this: map.connect ''-/:title[/*]'' The [/*] would indicate additional optional url directories. The "rest" of the url. Is this planned or is it already possible with routes? I know it is possible with mod_rewrite, but I think this shouldn''t be needed, right? Sascha
Alexey Verkhovsky
2005-Feb-19 14:24 UTC
Re: Routing: How do I use what is left from an URL
Sascha Ebach wrote:> /-/articles/ruby/rails/WTSCMSTCPBUWROR > I don''t know how long the path is going to be. The page could lie in > root or have several directory levels. > As soon as I try to use the above route I get a routing error.I have a similar problem, and the only available solution to handle a variable number of slashes as of two days ago was to escape them, so your path becomes something like: articles/ruby%2Frails%2FWTSCMSTCPBUWROR Not nice, I know. There is some commit in the trunk that enables Routes to deal with regexps. I haven''t looked at it closely yet. It may cope with this problem, I don''t know. Ulysses: see? Another unsatisfied customer who wants '':foo/:bar...'' mapping :) -- Best regards, Alexey Verkhovsky Ruby Forum: http://ruby-forum.org (moderator) RForum: http://rforum.andreas-s.net (co-author) Instiki: http://instiki.org (maintainer)
Alexey Verkhovsky wrote:> articles/ruby%2Frails%2FWTSCMSTCPBUWROR > > Not nice, I know.No, that defeats the purpose of nice urls.> There is some commit in the trunk that enables Routes to deal with > regexps. I haven''t looked at it closely yet. It may cope with this > problem, I don''t know.I have also seen the commit, but I don''t think it is usable yet. At the moment routes seem to say "You can do anything you want to, as long as you don''t mess with the slashes..." > Ulysses: see? Another unsatisfied customer who wants '':foo/:bar...'' > mapping :) Yeah, it would be very nice if the aforementioned were possible. Sascha
On 19.2.2005, at 16:24, Alexey Verkhovsky wrote:> > Ulysses: see? Another unsatisfied customer who wants '':foo/:bar...'' > mapping :)Count me in, too. It''s an absolute requirement for a CMS with pretty, hierarchic url''s. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> > Ulysses: see? Another unsatisfied customer who wants '':foo/:bar...'' > > mapping :) > > Count me in, too. It''s an absolute requirement for a CMS with pretty, > hierarchic url''s.Me too. I''ve only been playing with rails for two days and I''ve already run into this limitation myself. -- Bob Aman
This may work! Just messing mind you :) map.connect '':controller/:action/:id'' begin map.recognise! rescue path = '':section/:a/:b/:c/:d'' map.connect path, :controller => ''page'', :action => ''read'', :title => ''home'', :a => nil, :b => nil, :c => nil, :d => nil end On Sat, 19 Feb 2005 12:45:40 -0500, Bob Aman <vacindak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Ulysses: see? Another unsatisfied customer who wants '':foo/:bar...'' > > > mapping :) > > > > Count me in, too. It''s an absolute requirement for a CMS with pretty, > > hierarchic url''s. > > Me too. I''ve only been playing with rails for two days and I''ve > already run into this limitation myself. > -- > Bob Aman > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >