Hi, I have these two lines in my routes.rb file: map.connect ''/'', :controller => ''home'' # Install the default route as the lowest priority. map.connect '':controller/:action/:id'' Connecting to localhost:3000/ indeed loads the "home" controller, but in an my .rhtml there''s <%= link_to ''Home'', :controller => ''home'' %> which in turn renders a link to localhost:3000/home when I expected localhost:3000/ Any ideas as to why this happens? I was under the impression that patterns specified first would take presedence over later ones. Jeroen
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Oct 17, 2005, at 2:36 AM, Jeroen Houben wrote:> Hi, > > I have these two lines in my routes.rb file: > > map.connect ''/'', :controller => ''home'' > > # Install the default route as the lowest priority. > map.connect '':controller/:action/:id'' > > Connecting to localhost:3000/ indeed loads the "home" controller, > but in an my .rhtml there''s <%= link_to ''Home'', :controller => > ''home'' %> which in turn renders a link to localhost:3000/home when > I expected localhost:3000/ > > Any ideas as to why this happens? I was under the impression that > patterns specified first would take presedence over later ones.I''m not sure why you get that error, but named routes are good for this sort of thing: map.index ''/'', :controller => ''home'' Then, do a <%= link_to ''Home'', index_url %> in your view(s). Joe Van Dyk http://www.pinkpucker.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (Darwin) iD8DBQFDU3u8sWh6/7z1gt4RAp3BAKCqkwq71MbWP/Q96Iz4NO1Ze0FA6ACgsWJ6 +6X/pzn+fuBYq7x0OM4SGI8=eSAX -----END PGP SIGNATURE-----
you can change your link in you .rhtml file from <%= link_to ''Home'', :controller => ''home'' %> to <%= link_to ''Home'', ''/'' %> Regards, Francois Paul Jeroen Houben wrote:> Hi, > > I have these two lines in my routes.rb file: > > map.connect ''/'', :controller => ''home'' > > # Install the default route as the lowest priority. > map.connect '':controller/:action/:id'' > > Connecting to localhost:3000/ indeed loads the "home" controller, but > in an my .rhtml there''s <%= link_to ''Home'', :controller => ''home'' %> > which in turn renders a link to localhost:3000/home when I expected > localhost:3000/ > > Any ideas as to why this happens? I was under the impression that > patterns specified first would take presedence over later ones. > > Jeroen > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Joe Van Dyk wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Oct 17, 2005, at 2:36 AM, Jeroen Houben wrote: > >> Hi, >> >> I have these two lines in my routes.rb file: >> >> map.connect ''/'', :controller => ''home'' >> >> # Install the default route as the lowest priority. >> map.connect '':controller/:action/:id'' >> >> Connecting to localhost:3000/ indeed loads the "home" controller, but >> in an my .rhtml there''s <%= link_to ''Home'', :controller => ''home'' %> >> which in turn renders a link to localhost:3000/home when I expected >> localhost:3000/ >> >> Any ideas as to why this happens? I was under the impression that >> patterns specified first would take presedence over later ones. > > > I''m not sure why you get that error, but named routes are good for this > sort of thing: > > map.index ''/'', :controller => ''home'' > > Then, do a <%= link_to ''Home'', index_url %> in your view(s). >Indeed I looked at named routes. I used the exact example you wrote above, but it didn''t work. It generates a link to http://localhost:3000/home My complete routes.rb file: ActionController::Routing::Routes.draw do |map| # Add your own custom routes here. # The priority is based upon order of creation: first created -> highest priority. # Here''s a sample route: # map.connect ''products/:id'', :controller => ''catalog'', :action => ''view'' # Keep in mind you can assign values other than :controller and :action # You can have the root of your site routed by hooking up '''' # -- just remember to delete public/index.html. map.index ''/'', :controller => ''home'' # Install the default route as the lowest priority. map.connect '':controller/:action/:id'' end
Francois Paul wrote:> > you can change your link in you .rhtml file from > > <%= link_to ''Home'', :controller => ''home'' %> > > to > > <%= link_to ''Home'', ''/'' %> >Sure, but what if one day I move my application root from http://localhost:3000/ to http://localhost:3000/work/apps/mymovedapp ? I''d have change all the references to ''/'' Jeroen
Hi Jeroen, Try using: map.connect '''', :controller => ''home'' I believe that will give you the url you''re looking for. Sanford Jeroen Houben wrote:> Hi, > > I have these two lines in my routes.rb file: > > map.connect ''/'', :controller => ''home'' > > # Install the default route as the lowest priority. > map.connect '':controller/:action/:id'' > > Connecting to localhost:3000/ indeed loads the "home" controller, but in > an my .rhtml there''s <%= link_to ''Home'', :controller => ''home'' %> which > in turn renders a link to localhost:3000/home when I expected > localhost:3000/ > > Any ideas as to why this happens? I was under the impression that > patterns specified first would take presedence over later ones. > > Jeroen