Hi all, Relative RoR newbie here. I''ve been researching routes, but I haven''t found what I need. I have an app which has one primary controller (store) which provides a web UI (there are several other controllers for internal ''stuff''). What I''m trying to do is _completely_ remove the controller name from all generated URLs. Here''s what I currently have in the routes file: ActionController::Routing::Routes.draw do |map| ... map.connect '''', :controller => ''store'' map.connect '':controller/:action/:id'' ... end In my templates, the following link_to <%= link_to "Home", :action => "index" -%> generates the following URL: http://localhost:3000/ Any action other than ''index'' seems to insert the controller name into the URL. For example, this link_to <%= link_to "News", :action => "display_news" -%> generates the following URL: http://localhost:3000/store/display_news What I would like the previous link_to to generate is: http://localhost:3000/display_news Any help is appreciated. Carpe viam, Mike Michael Larocque Chief Cook and Bottle Washer Prolumina Communications Inc. http://prolumina.com/~mlarocque/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Larocque
2006-Nov-20 20:35 UTC
Re: removing ''controller_id'' completely from URLs
On 20 November 2006, at 11:32 , Michael Larocque wrote:> Hi all, > > Relative RoR newbie here. I''ve been researching routes, but I > haven''t found what I need. > > I have an app which has one primary controller (store) which > provides a web UI (there are several other controllers for internal > ''stuff''). What I''m trying to do is _completely_ remove the > controller name from all generated URLs. > > Here''s what I currently have in the routes file: > > ActionController::Routing::Routes.draw do |map| > ... > < /SPAN> map.connect '''', :controller => ''store'' > map.connect '':controller/:action/:id'' > ... > end >Hmm, not sure how that got munged. routes.rb looks like this: ActionController::Routing::Routes.draw do |map| map.connect '''', :controller => ''store'' map.connect '':controller/:action/:id'' end> In my templates, the following link_to > > <%= link_to "Home", :action => "index" -%> > > generates the following URL: > > http://localhost:3000/ > > Any action other than ''index'' seems to insert the controller name > into the URL. For example, this link_to > > <%= link_to "News", :action => "display_news" -%> > > generates the following URL: > > http://localhost:3000/store/display_news > > What I would like the previous link_to to generate is: > > http://localhost:3000/display_news > > Any help is appreciated. > > Carpe viam, > Mike > > Michael Larocque > Chief Cook and Bottle Washer > Prolumina Communications Inc. > http://prolumina.com/~mlarocque/ > > > > >Carpe viam, Mike Michael Larocque Chief Cook and Bottle Washer Prolumina Communications Inc. http://prolumina.com/~mlarocque/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > What I would like the previous link_to to generate is: > > > http://localhost:3000/display_news >Try adding the following to your routes.rb.. it should have the desired result. map.connect ''/display_news'', :controller => ''store'', :action => ''display_news'' Neil --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Larocque
2006-Nov-21 02:35 UTC
Re: removing ''controller_id'' completely from URLs
On 2006-Nov-20, at 15:25 , NeilB wrote:> >>> What I would like the previous link_to to generate is: >> >>> http://localhost:3000/display_news >> > Try adding the following to your routes.rb.. it should have the > desired > result. > > map.connect ''/display_news'', :controller => ''store'', :action => > ''display_news'' > > NeilBut that requires updates to routes.rb whenever I add a method to the store controller. Not good. Essentially, any time I generate a link to an action within the ''store'' controller, I want the the URL to be of the form: http://example.com/action/whatever... and _not_ http://example.com/store/action/whatever... There''s got to be a simple way to do this. Carpe viam, Mike Michael Larocque Chief Cook and Bottle Washer Prolumina Communications Inc. http://prolumina.com/~mlarocque/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Don''t have rails here to test this out on but I believe this would work: map.root ''/:action'', :controller => ''store'' This I believe will capture all "http://server:port/:action" calls and route them to the StoreController and the proper action. I usually name my routes for easy link generation, that''s why it''s map.root instead of map.connect. Curtis ----- Original Message ----- From: "Michael Larocque" <mlarocque-aVEx+fnPBL6B+jHODAdFcQ@public.gmane.org> To: <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Sent: Monday, November 20, 2006 9:35 PM Subject: [Rails] Re: removing ''controller_id'' completely from URLs> > > On 2006-Nov-20, at 15:25 , NeilB wrote: > > > > >>> What I would like the previous link_to to generate is: > >> > >>> http://localhost:3000/display_news > >> > > Try adding the following to your routes.rb.. it should have the > > desired > > result. > > > > map.connect ''/display_news'', :controller => ''store'', :action => > > ''display_news'' > > > > Neil > > But that requires updates to routes.rb whenever I add a method to the > store controller. Not good. > > Essentially, any time I generate a link to an action within the > ''store'' controller, I want the the URL to be of the form: > > http://example.com/action/whatever... > > and _not_ > > http://example.com/store/action/whatever... > > There''s got to be a simple way to do this. > > Carpe viam, > Mike > > Michael Larocque > Chief Cook and Bottle Washer > Prolumina Communications Inc. > http://prolumina.com/~mlarocque/ > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Larocque
2006-Nov-21 15:07 UTC
Re: removing ''controller_id'' completely from URLs
On 20 November 2006, at 19:50 , Curtis Hatter wrote:> > Don''t have rails here to test this out on but I believe this would > work: > > map.root ''/:action'', :controller => ''store'' > > This I believe will capture all "http://server:port/:action" calls > and route > them to the StoreController and the proper action. > > I usually name my routes for easy link generation, that''s why it''s > map.root > instead of map.connect. > > CurtisThanks Curtis. That seems to have pointed me in the right direction. Currently, I have ActionController::Routing::Routes.draw do |map| map.connect ''account'', :controller => ''account'' # login map.root ''/:action/:id'', :controller => ''store'' map.connect '':controller/:action/:id'' end and this seems to work. Carpe viam, Mike Michael Larocque Chief Cook and Bottle Washer Prolumina Communications Inc. http://prolumina.com/~mlarocque/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
<curtis.hatter-xOqKmqBdiMhF6kxbq+BtvQ@public.gmane.org>
2006-Nov-21 15:46 UTC
Re: removing ''controller_id'' completely from URLs
The order of the routes makes a big difference. Out of curiosity what happens
currently if you go to a :controller/:action (leaving out the
''/:id'' portion?)
For example, if you have ''cart'' controller and you try to
access http://server:port/cart/index does it work? I''m wondering if the
map.root rule will match it instead thinking that you mean
''cart'' = '':action'' and
''index'' = '':id''. You should be fine as long
as it''s '':controller/:action/:id'' since that
won''t match the map.root rule (cause it has 3 parts). Also what happens
if you do http://server.port/cart (which I would cause you want to be the cart
controller with the default action of index).
If that does happen you may want to move map.root to the bottom and specify a
requirements on '':controller/:action/:id'' such that it
doesn''t match your store controller.
map.connect '':controller/:action/:id, :requirements => { :controller
=> /(?!store)/ }
I believe that requirement regex will work (haven''t tried zero-width
negative look-ahead assertions in routes yet.
Just some things you might want to look into.
Curtis
----- Original Message -----
From: Michael Larocque <mlarocque-aVEx+fnPBL6B+jHODAdFcQ@public.gmane.org>
Date: Tuesday, November 21, 2006 10:14
Subject: [Rails] Re: removing ''controller_id'' completely from
URLs
To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
>
>
> On 20 November 2006, at 19:50 , Curtis Hatter wrote:
>
> >
> > Don''t have rails here to test this out on but I believe this
> would
> > work:
> >
> > map.root ''/:action'', :controller =>
''store''
> >
> > This I believe will capture all "http://server:port/:action"
> calls
> > and route
> > them to the StoreController and the proper action.
> >
> > I usually name my routes for easy link generation, that''s why
> it''s
> > map.root
> > instead of map.connect.
> >
> > Curtis
>
> Thanks Curtis. That seems to have pointed me in the right
> direction.
> Currently, I have
>
> ActionController::Routing::Routes.draw do |map|
> map.connect ''account'', :controller =>
> ''account'' # login
> map.root ''/:action/:id'', :controller =>
''store''
> map.connect '':controller/:action/:id''
> end
>
> and this seems to work.
>
> Carpe viam,
> Mike
>
> Michael Larocque
> Chief Cook and Bottle Washer
> Prolumina Communications Inc.
> http://prolumina.com/~mlarocque/
>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Michael Larocque
2006-Nov-21 16:13 UTC
Re: removing ''controller_id'' completely from URLs
On 21 November 2006, at 08:46 , <curtis.hatter-xOqKmqBdiMhF6kxbq+BtvQ@public.gmane.org> <curtis.hatter-xOqKmqBdiMhF6kxbq+BtvQ@public.gmane.org> wrote:> > The order of the routes makes a big difference. Out of curiosity > what happens currently if you go to a :controller/:action (leaving > out the ''/:id'' portion?) > > For example, if you have ''cart'' controller and you try to access > http://server:port/cart/index does it work? I''m wondering if the > map.root rule will match it instead thinking that you mean ''cart'' = > '':action'' and ''index'' = '':id''. You should be fine as long as it''s > '':controller/:action/:id'' since that won''t match the map.root rule > (cause it has 3 parts). Also what happens if you do http:// > server.port/cart (which I would cause you want to be the cart > controller with the default action of index). > > If that does happen you may want to move map.root to the bottom and > specify a requirements on '':controller/:action/:id'' such that it > doesn''t match your store controller. > > map.connect '':controller/:action/:id, :requirements => > { :controller => /(?!store)/ } > > I believe that requirement regex will work (haven''t tried zero- > width negative look-ahead assertions in routes yet. > > Just some things you might want to look into. > CurtisThanks Curtis, Yeah, I''m looking into this some more - after further testing I was seeing several problems. I''m looking into this now - thanks for the suggestions above. Carpe viam, Mike Michael Larocque Chief Cook and Bottle Washer Prolumina Communications Inc. http://prolumina.com/~mlarocque/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Larocque
2006-Nov-23 17:39 UTC
Re: removing ''controller_id'' completely from URLs
On 21 November 2006, at 08:46 , <curtis.hatter-xOqKmqBdiMhF6kxbq+BtvQ@public.gmane.org> <curtis.hatter-xOqKmqBdiMhF6kxbq+BtvQ@public.gmane.org> wrote:> > If that does happen you may want to move map.root to the bottom and > specify a requirements on '':controller/:action/:id'' such that it > doesn''t match your store controller. > > map.connect '':controller/:action/:id, :requirements => > { :controller => /(?!store)/ } > > I believe that requirement regex will work (haven''t tried zero- > width negative look-ahead assertions in routes yet. > > Just some things you might want to look into. > CurtisThanks Curtis. That seems to have done the trick. Carpe viam, Mike Michael Larocque Chief Cook and Bottle Washer Prolumina Communications Inc. http://prolumina.com/~mlarocque/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---