Infinit
2007-Dec-01 10:19 UTC
How to make will_paginate generated URL search engine friendly
I m using will_paginate plugin to do the pagination. And I find that the generated URL is like the following format: http://localhost:3000/site?page=2 http://localhost:3000/site?page=3 ...... how can I let it generate URLs like the following format:(or any other formats which is search engine friendly). http://localhost:3000/site/page/2 http://localhost:3000/site/page/4 appreciate for your help. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
rubynuby
2007-Dec-01 19:27 UTC
Re: How to make will_paginate generated URL search engine friendly
this is how I have it working. i''s not necessarily the best way.
I''m
a newbie.
in routes.rb, after map.resources :posts
# anything like /2 (just a page#) should go to my default controller
posts
map.connect '':page'',
:action => ''index'',
:controller => ''posts'',
:requirements => { :page => /\d+/},
:page => nil
# anything like /posts/tags/rails/2 should go to the appropriate
controller and action
map.connect '':controller/:action/:id/:page'',
:requirements => { :page => /\d+/}
Note: there''s no page => nil here. page must be present to trigger
this rule, otherwise it thinks something like /posts/johnny/2 is
asking for action johnny with id 2.
# anything like /posts/johnny/2 should is a show action. i.e., show
page 2 of johnny''s posts.
map.connect '':controller/:id/:page'',
:requirements => { :page => /\d+/},
:action => ''show'',
:page => nil
Note: here the page CAN be nil, so it''ll generate the shortest URL,
i.e., /posts/johnny instead of /posts/johnny/1
these are RESTful routes I''m using, which you can modify to suit.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
rubynuby
2007-Dec-01 19:53 UTC
Re: How to make will_paginate generated URL search engine friendly
sorry, I just found a problem with my scheme. it cannot handle /:controller/:page (action index, page 2) when controller is something other than my default controller. In fact I don''t think there''s a way to distinguish between /controller/page and /controller/id unless your id has some unique pattern other than \d+ I''ll let someone more knowledgable chime in :) On Dec 1, 11:27 am, rubynuby <dear...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> this is how I have it working. i''s not necessarily the best way. I''m > a newbie. > > in routes.rb, after map.resources :posts > > # anything like /2 (just a page#) should go to my default controller > posts > > map.connect '':page'', > :action => ''index'', > :controller => ''posts'', > :requirements => { :page => /\d+/}, > :page => nil > > # anything like /posts/tags/rails/2 should go to the appropriate > controller and action > > map.connect '':controller/:action/:id/:page'', > :requirements => { :page => /\d+/} > > Note: there''s no page => nil here. page must be present to trigger > this rule, otherwise it thinks something like /posts/johnny/2 is > asking for action johnny with id 2. > > # anything like /posts/johnny/2 should is a show action. i.e., show > page 2 of johnny''s posts. > > map.connect '':controller/:id/:page'', > :requirements => { :page => /\d+/}, > :action => ''show'', > :page => nil > > Note: here the page CAN be nil, so it''ll generate the shortest URL, > i.e., /posts/johnny instead of /posts/johnny/1 > > these are RESTful routes I''m using, which you can modify to suit.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Infinit
2007-Dec-03 04:50 UTC
Re: How to make will_paginate generated URL search engine friendly
Thanks for your reply :-) On Dec 2, 3:53 am, rubynuby <dear...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> sorry, I just found a problem with my scheme. it cannot handle > > /:controller/:page > > (action index, page 2) > > when controller is something other than my default controller. In > fact I don''t think there''s a way to distinguish between > > /controller/page and /controller/id unless your id has some unique > pattern other than \d+ > > I''ll let someone more knowledgable chime in :) > > On Dec 1, 11:27 am, rubynuby <dear...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > this is how I have it working. i''s not necessarily the best way. I''m > > a newbie. > > > in routes.rb, after map.resources :posts > > > # anything like /2 (just a page#) should go to my default controller > > posts > > > map.connect '':page'', > > :action => ''index'', > > :controller => ''posts'', > > :requirements => { :page => /\d+/}, > > :page => nil > > > # anything like /posts/tags/rails/2 should go to the appropriate > > controller and action > > > map.connect '':controller/:action/:id/:page'', > > :requirements => { :page => /\d+/} > > > Note: there''s no page => nil here. page must be present to trigger > > this rule, otherwise it thinks something like /posts/johnny/2 is > > asking for action johnny with id 2. > > > # anything like /posts/johnny/2 should is a show action. i.e., show > > page 2 of johnny''s posts. > > > map.connect '':controller/:id/:page'', > > :requirements => { :page => /\d+/}, > > :action => ''show'', > > :page => nil > > > Note: here the page CAN be nil, so it''ll generate the shortest URL, > > i.e., /posts/johnny instead of /posts/johnny/1 > > > these are RESTful routes I''m using, which you can modify to suit.- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---