Is it possible to change a controller''s default action - say from "index" to "list"? mydomain.com/item (I want it to "list" rather than "index") thanks csn __________________________________ Yahoo! Mail - PC Magazine Editors'' Choice 2005 http://mail.yahoo.com
Francois Beausoleil
2005-Nov-12 05:27 UTC
Re: Possible to change controller''s default action?
Hi ! 2005/11/11, CSN <cool_screen_name90001@yahoo.com>:> Is it possible to change a controller's default action > - say from "index" to "list"?Redirect to :list, or render :list should do it ! If you look at scaffolded code, the second solution is the one used. Hope that helps ! François _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Nov 11, 2005, at 10:27 PM, Francois Beausoleil wrote:> Hi ! > > 2005/11/11, CSN <cool_screen_name90001-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>: >> Is it possible to change a controller''s default action >> - say from "index" to "list"? > > Redirect to :list, or render :list should do it ! > > If you look at scaffolded code, the second solution is the one used.You can also set up a route: map.connect "special/:action", :controller => "special", :action => "list" - Jamis
Right, but I have different templates (displaying different stuff) for index and list. csn --- Francois Beausoleil <francois.beausoleil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi ! > > 2005/11/11, CSN <cool_screen_name90001-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>: > > Is it possible to change a controller''s default > action > > - say from "index" to "list"? > > Redirect to :list, or render :list should do it ! > > If you look at scaffolded code, the second solution > is the one used. > > Hope that helps ! > François > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >__________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com
On 12.11.2005, at 10.15, CSN wrote:> > Right, but I have different templates (displaying > different stuff) for index and list.So you have both actions, index and list, that do different things. However, you don''t want the action index to be the default one. Am I right? I don''t really understand why, since index is *the* name for a default file of a "folder". If you use page caching, you will probably run into trouble for this exact reason, even if you use the trick I''m about to tell you. So caveat emptor. Put this into your routes: map.connect "special/", :controller => "special", :action => "list" //jarkko> > csn > > > --- Francois Beausoleil > <francois.beausoleil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Hi ! >> >> 2005/11/11, CSN <cool_screen_name90001-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>: >>> Is it possible to change a controller''s default >> action >>> - say from "index" to "list"? >> >> Redirect to :list, or render :list should do it ! >> >> If you look at scaffolded code, the second solution >> is the one used. >> >> Hope that helps ! >> François >>> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > > > __________________________________ > Yahoo! FareChase: Search multiple travel sites in one click. > http://farechase.yahoo.com > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Well, I just wanted my URLs to be as so: mysite.com -> item''s index action (which has different queries and layout than ''list'') mysite.com/items -> item''s list action mysite.com/item/id -> item''s show action and there are other URLs: mysite.com/member -> member''s index/show action (uses session) mysite.com/members -> member''s list action This is likely achievable with routes, and I briefly tried, but it became complicated (I didn''t know there would be caching issues either, which I haven''t gotten into yet). csn --- Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> On 12.11.2005, at 10.15, CSN wrote: > > > > > Right, but I have different templates (displaying > > different stuff) for index and list. > > So you have both actions, index and list, that do > different things. > However, you don''t want the action index to be the > default one. Am I > right? > > I don''t really understand why, since index is *the* > name for a > default file of a "folder". If you use page caching, > you will > probably run into trouble for this exact reason, > even if you use the > trick I''m about to tell you. So caveat emptor. > > Put this into your routes: > > map.connect "special/", :controller => "special", > :action => "list" > > //jarkko > > > > > > > csn > > > > > > --- Francois Beausoleil > > <francois.beausoleil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > >> Hi ! > >> > >> 2005/11/11, CSN > <cool_screen_name90001-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>: > >>> Is it possible to change a controller''s default > >> action > >>> - say from "index" to "list"? > >> > >> Redirect to :list, or render :list should do it ! > >> > >> If you look at scaffolded code, the second > solution > >> is the one used. > >> > >> Hope that helps ! > >> Françoiscraig __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com
On 14.11.2005, at 11.39, CSN wrote:> > Well, I just wanted my URLs to be as so: > > mysite.com -> item''s index action (which has different > queries and layout than ''list'') > mysite.com/items -> item''s list action > mysite.com/item/id -> item''s show action > > and there are other URLs: > > mysite.com/member -> member''s index/show action (uses > session) > mysite.com/members -> member''s list action > > This is likely achievable with routes, and I briefly > tried, but it became complicated (I didn''t know there > would be caching issues either, which I haven''t gotten > into yet).There shouldn''t be any issues with the url''s described above. They''re just url''s and you can map them to controllers/actions using routes. What do you mean by it becoming complicated? If you want that the url''s in your app behave in some other way than the normal :controller/:action/:id, you need to tell it to Rails. It can''t AFAIK read your mind (yet). So, here we go, nothing special or extremely complicated: map.connect "", :controller => "item", :action => "index" map.connect "items", :controller => "item", :action => "list" map.connect "item/:id", :controller => "item", :action => "show" map.connect "member", :controller => "member", :action => "index" # You don''t really need this, this obeys the standard Rails convention map.connect "members", :controller => "member", :action => "list" You might also want to take a look at named routes. //jarkko> > csn > > > --- Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote: > >> On 12.11.2005, at 10.15, CSN wrote: >> >>> >>> Right, but I have different templates (displaying >>> different stuff) for index and list. >> >> So you have both actions, index and list, that do >> different things. >> However, you don''t want the action index to be the >> default one. Am I >> right? >> >> I don''t really understand why, since index is *the* >> name for a >> default file of a "folder". If you use page caching, >> you will >> probably run into trouble for this exact reason, >> even if you use the >> trick I''m about to tell you. So caveat emptor. >> >> Put this into your routes: >> >> map.connect "special/", :controller => "special", >> :action => "list" >> >> //jarkko >> >> >> >>> >>> csn >>> >>> >>> --- Francois Beausoleil >>> <francois.beausoleil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> Hi ! >>>> >>>> 2005/11/11, CSN >> <cool_screen_name90001-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>: >>>>> Is it possible to change a controller''s default >>>> action >>>>> - say from "index" to "list"? >>>> >>>> Redirect to :list, or render :list should do it ! >>>> >>>> If you look at scaffolded code, the second >> solution >>>> is the one used. >>>> >>>> Hope that helps ! >>>> François > > > craig > > > > __________________________________ > Yahoo! FareChase: Search multiple travel sites in one click. > http://farechase.yahoo.com > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Cool, thanks. Is there a URL which has documentation for ''named routes''? There doesn''t appear to be anything map/route related at api.rubyonrails.org (figured it''d be ActionController::Routes or something). And in what release is mind-reading planned? thanks csn --- Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> > On 14.11.2005, at 11.39, CSN wrote: > > > > > Well, I just wanted my URLs to be as so: > > > > mysite.com -> item''s index action (which has > different > > queries and layout than ''list'') > > mysite.com/items -> item''s list action > > mysite.com/item/id -> item''s show action > > > > and there are other URLs: > > > > mysite.com/member -> member''s index/show action > (uses > > session) > > mysite.com/members -> member''s list action > > > > This is likely achievable with routes, and I > briefly > > tried, but it became complicated (I didn''t know > there > > would be caching issues either, which I haven''t > gotten > > into yet). > > There shouldn''t be any issues with the url''s > described above. They''re > just url''s and you can map them to > controllers/actions using routes. > What do you mean by it becoming complicated? If you > want that the > url''s in your app behave in some other way than the > > normal :controller/:action/:id, you need to tell it > to Rails. It > can''t AFAIK read your mind (yet). > > So, here we go, nothing special or extremely > complicated: > > map.connect "", :controller => "item", :action => > "index" > map.connect "items", :controller => "item", :action > => "list" > map.connect "item/:id", :controller => "item", > :action => "show" > > map.connect "member", :controller => "member", > :action => "index" # > You don''t really need this, this obeys the standard > Rails convention > map.connect "members", :controller => "member", > :action => "list" > > You might also want to take a look at named routes. > > //jarkko > > > > > > csn > > > > > > --- Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote: > > > >> On 12.11.2005, at 10.15, CSN wrote: > >> > >>> > >>> Right, but I have different templates > (displaying > >>> different stuff) for index and list. > >> > >> So you have both actions, index and list, that do > >> different things. > >> However, you don''t want the action index to be > the > >> default one. Am I > >> right? > >> > >> I don''t really understand why, since index is > *the* > >> name for a > >> default file of a "folder". If you use page > caching, > >> you will > >> probably run into trouble for this exact reason, > >> even if you use the > >> trick I''m about to tell you. So caveat emptor. > >> > >> Put this into your routes: > >> > >> map.connect "special/", :controller => > "special", > >> :action => "list" > >> > >> //jarkko > >> > >> > >> > >>> > >>> csn > >>> > >>> > >>> --- Francois Beausoleil > >>> <francois.beausoleil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >>> > >>>> Hi ! > >>>> > >>>> 2005/11/11, CSN > >> <cool_screen_name90001-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>: > >>>>> Is it possible to change a controller''s > default > >>>> action > >>>>> - say from "index" to "list"? > >>>> > >>>> Redirect to :list, or render :list should do it > ! > >>>> > >>>> If you look at scaffolded code, the second > >> solution > >>>> is the one used. > >>>> > >>>> Hope that helps ! > >>>> François > > > > > > craig > > > > > > > > __________________________________ > > Yahoo! FareChase: Search multiple travel sites in > one click. > > http://farechase.yahoo.com > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >craig __________________________________ Yahoo! Mail - PC Magazine Editors'' Choice 2005 http://mail.yahoo.com
On 14.11.2005, at 12.16, CSN wrote:> > Cool, thanks. Is there a URL which has documentation > for ''named routes''? There doesn''t appear to be > anything map/route related at api.rubyonrails.org > (figured it''d be ActionController::Routes or > something).Sorry, forgot that. http://wiki.rubyonrails.com/rails/pages/NamedRoutes> > And in what release is mind-reading planned?There is a debate going on on whether that would make Rails a bit too ''opinionated''. But we''ll see. //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