Hi,
I want to have the following URL structure
/music
/movies
etc. for categories of the site.
/about
/help
etc. for static pages.
Both types auf URLs should be generated dynamically.
But how do I route them?
map.connect ''/:category/'',
:controller=>''magazine'',
:action=>''index'',
:rubrik => // #should be generated from database, but how?
map.connect ''/:page/'',
:controller=>''magazine'',
:action=>''page'',
:page => /[(help)|(about)]/ #but should also be generated dynamically
Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Ernst Beiglböck wrote:> Hi, > I want to have the following URL structure > /music > /movies > etc. for categories of the site. > > /about > /help > etc. for static pages. > > Both types auf URLs should be generated dynamically. > > But how do I route them? > > map.connect ''/:category/'', :controller=>''magazine'', :action=>''index'', > :rubrik => // #should be generated from database, but how? > > map.connect ''/:page/'', :controller=>''magazine'', :action=>''page'', > :page => /[(help)|(about)]/ #but should also be generated dynamically > > Thanks.http://www.aflatter.de/typo/articles/2007/01/14/dynamic-routing-in-rails I run into one article when looking for a way to implement routes from database and multi-language URL''s. It could be of interest to you, I didn''t try it yet: http://www.aflatter.de/typo/articles/2007/01/14/dynamic-routing-in-rails best regards, Bojan -- Bojan Mihelac Informatika Mihelac, Bojan Mihelac s.p. | www.informatikamihelac.com -> tools, scripts, tricks from our code lab: http://source.mihelac.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sounds interesting.
But I''ve already found a simpler solution, without making a plugin:
map.connect ''/'', :controller
=>''magazin'', :action=>''index''
map.connect ''/:rubrik/'',
:controller=>''magazin'',
:action=>''index'',
:rubrik => Regexp.new(Category.find(:all).collect {|o|
"(#{o.name})"}.join(''|'').downcase)
map.connect ''/:page/'',
:controller=>''magazin'',
:action=>''page'',
:page => Regexp.new(Page.find(:all).collect {|o|
"(#{o.title})"}.join(''|'').downcase)
map.slug ''/:slug/'', :controller
=>''magazin'', :action=>''artikel''
You can create an Regexp from an array. Great. But maybe slow?
nice regards,
ernst
On 2/25/07, Bojan Mihelac <lists-3SxN1WY3PMJAfugRpC6u6w@public.gmane.org>
wrote:>
> Ernst Beiglböck wrote:
> > Hi,
> > I want to have the following URL structure
> > /music
> > /movies
> > etc. for categories of the site.
> >
> > /about
> > /help
> > etc. for static pages.
> >
> > Both types auf URLs should be generated dynamically.
> >
> > But how do I route them?
> >
> > map.connect ''/:category/'',
:controller=>''magazine'',
:action=>''index'',
> > :rubrik => // #should be generated from database, but how?
> >
> > map.connect ''/:page/'',
:controller=>''magazine'',
:action=>''page'',
> > :page => /[(help)|(about)]/ #but should also be generated
dynamically
> >
> > Thanks.
>
> http://www.aflatter.de/typo/articles/2007/01/14/dynamic-routing-in-rails
>
> I run into one article when looking for a way to implement routes from
> database and multi-language URL''s. It could be of interest to you,
I
> didn''t try it yet:
>
> http://www.aflatter.de/typo/articles/2007/01/14/dynamic-routing-in-rails
>
> best regards,
> Bojan
>
>
>
>
> --
> Bojan Mihelac
> Informatika Mihelac, Bojan Mihelac s.p. | www.informatikamihelac.com
> -> tools, scripts, tricks from our code lab: http://source.mihelac.org
>
> >
>
--
wer viel lest ist viel gebildet.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Ernst Beiglböck wrote:> I want to have the following URL structure > /music > /movies > etc. for categories of the site. > > /about > /help > etc. for static pages.This provides a custom homepage for any user: site.com/my_name map.connect '':controller/:action/:id'' map.connect ''*login'', :controller => ''account'', :action => ''home_page'' The trick is that param[:login] arrives in your controller. I suspect I should have tested my system with this: assert_routing ''/mr_smith'', :controller => ''account'', :action => ''home_page'', :login => ''mr_smith'' Now you just read a *param in your controller, and render the appropriate response. -- Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi -- On 2/25/07, Phlip <phlip2005-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Ernst Beiglböck wrote: > > > I want to have the following URL structure > > /music > > /movies > > etc. for categories of the site. > > > > /about > > /help > > etc. for static pages. > > This provides a custom homepage for any user: site.com/my_name > > map.connect '':controller/:action/:id'' > map.connect ''*login'', :controller => ''account'', :action => ''home_page'' > > The trick is that param[:login] arrives in your controller. > > I suspect I should have tested my system with this: > > assert_routing ''/mr_smith'', > :controller => ''account'', > :action => ''home_page'', > :login => ''mr_smith'' > > Now you just read a *param in your controller, and render the appropriate > response.I think you probably want :login, rather than *login. *login gives you a route glob, which might contain any number of fields. They''ll be delivered to the action in an array (params[:login]), whereas with :login you''ve got just one wildcard field, which will be delivered as a string. There''s a bit of a potential problem with this route, though. If someone has a login name that''s the same as a controller, you might be in trouble: >> ActionController::Routing::Routes.recognize_path("/dblack") => {:login=>"dblack", :controller=>"account", :action=>"home_page"} >> ActionController::Routing::Routes.recognize_path("/questions") => {:controller=>"questions", :action=>"index"} If someone happens to sign up as "questions", their home page link won''t work. So it might be better to do something like: map.connect ''home/:login'', :controller => "account", :action => "home_page" which gives you: >> ActionController::Routing::Routes.recognize_path("/home/david") => {:login=>"david", :controller=>"account", :action=>"home_page"} >> ActionController::Routing::Routes.recognize_path("/home/questions") => {:login=>"questions", :controller=>"account", :action=>"home_page"} David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ernst Beiglböck wrote:> Sounds interesting. > But I''ve already found a simpler solution, without making a plugin: > > map.connect ''/'', :controller =>''magazin'', :action=>''index'' > map.connect ''/:rubrik/'', :controller=>''magazin'', :action=>''index'', > :rubrik => Regexp.new(Category.find(:all).collect {|o| > "(#{o.name})"}.join(''|'').downcase) > > map.connect ''/:page/'', :controller=>''magazin'', :action=>''page'', > :page => Regexp.new(Page.find(:all).collect {|o| > "(#{o.title})"}.join(''|'').downcase) > > map.slug ''/:slug/'', :controller =>''magazin'', :action=>''artikel'' > > You can create an Regexp from an array. Great. But maybe slow? > > nice regards, > ernst >Do you reload routes when category or page is added in database? best regards, Bojan -- Bojan Mihelac Informatika Mihelac, Bojan Mihelac s.p. | www.informatikamihelac.com -> tools, scripts, tricks from our code lab: http://source.mihelac.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I didn''t think of it, but now as you say it I think I better should ;) On 2/26/07, Bojan Mihelac <lists-3SxN1WY3PMJAfugRpC6u6w@public.gmane.org> wrote:> > Ernst Beiglböck wrote: > > Sounds interesting. > > But I''ve already found a simpler solution, without making a plugin: > > > > map.connect ''/'', :controller =>''magazin'', :action=>''index'' > > map.connect ''/:rubrik/'', :controller=>''magazin'', :action=>''index'', > > :rubrik => Regexp.new(Category.find(:all).collect {|o| > > "(#{o.name})"}.join(''|'').downcase) > > > > map.connect ''/:page/'', :controller=>''magazin'', :action=>''page'', > > :page => Regexp.new(Page.find(:all).collect {|o| > > "(#{o.title})"}.join(''|'').downcase) > > > > map.slug ''/:slug/'', :controller =>''magazin'', :action=>''artikel'' > > > > You can create an Regexp from an array. Great. But maybe slow? > > > > nice regards, > > ernst > > > > Do you reload routes when category or page is added in database? > > best regards, > Bojan > > > -- > Bojan Mihelac > Informatika Mihelac, Bojan Mihelac s.p. | www.informatikamihelac.com > -> tools, scripts, tricks from our code lab: http://source.mihelac.org > > > >-- wer viel lest ist viel gebildet. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---