Hi there, I wondered if anybody had any experience with having nested controllers?For example, I''d like a hierarchy something like this: /product /product/list /product/detail /product/detail/category I can''t find any documentation on this, so any advice/experience anybody might have would prove useful. N.B. This is for a generator which builds Views and Controllers from a hierarchy held in a DB, so I need something which will be flexible and anonymous. -Phil
kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org
2005-Jul-15 18:22 UTC
Re: Nested Controllers
I had asked the same question before and the general recommendation was to check out how Typo does it. Basically you create a base controller and subclass that. Check it out here: http://typo.leetsoft.com/trac/browser/trunk/app/controllers/admin/ http://typo.leetsoft.com/trac/> Hi there, > > I wondered if anybody had any experience with having nested > controllers?For example, I''d like a hierarchy something like this: > > /product > /product/list > /product/detail > /product/detail/category > > I can''t find any documentation on this, so any advice/experience > anybody might have would prove useful. > > N.B. This is for a generator which builds Views and Controllers from > a hierarchy held in a DB, so I need something which will be flexible > and anonymous. > > -Phil > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Justin French has a great tip/tutorial on doing just this... you may want to check it out: http://justinfrench.com/index.php?id=122 HTH! On 7/15/05, kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org <kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote:> I had asked the same question before and the general recommendation was to check out how Typo does it. Basically you create a base controller and subclass that. > > Check it out here: > http://typo.leetsoft.com/trac/browser/trunk/app/controllers/admin/ > http://typo.leetsoft.com/trac/ > > > > Hi there, > > > > I wondered if anybody had any experience with having nested > > controllers?For example, I''d like a hierarchy something like this: > > > > /product > > /product/list > > /product/detail > > /product/detail/category > > > > I can''t find any documentation on this, so any advice/experience > > anybody might have would prove useful. > > > > N.B. This is for a generator which builds Views and Controllers from > > a hierarchy held in a DB, so I need something which will be flexible > > and anonymous. > > > > -Phil > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- - Frank FrankManno.com <a href="http://www.spreadfirefox.com/?q=affiliates&id=2496&t=1">Get Firefox!</a>
Also check out this thread from the list a couple of days back: http://article.gmane.org/gmane.comp.lang.ruby.rails/14513 which seems similar to what you want. Cheers, C On 7/15/05, Frank Manno <frankmanno-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Justin French has a great tip/tutorial on doing just this... you may > want to check it out: > > http://justinfrench.com/index.php?id=122 > > HTH! > > On 7/15/05, kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org <kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote: > > I had asked the same question before and the general recommendation was to check out how Typo does it. Basically you create a base controller and subclass that. > > > > Check it out here: > > http://typo.leetsoft.com/trac/browser/trunk/app/controllers/admin/ > > http://typo.leetsoft.com/trac/ > > > > > > > Hi there, > > > > > > I wondered if anybody had any experience with having nested > > > controllers?For example, I''d like a hierarchy something like this: > > > > > > /product > > > /product/list > > > /product/detail > > > /product/detail/category > > > > > > I can''t find any documentation on this, so any advice/experience > > > anybody might have would prove useful. > > > > > > N.B. This is for a generator which builds Views and Controllers from > > > a hierarchy held in a DB, so I need something which will be flexible > > > and anonymous. > > > > > > -Phil > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > - Frank > FrankManno.com > > <a href="http://www.spreadfirefox.com/?q=affiliates&id=2496&t=1">Get > Firefox!</a> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Phil Powell wrote:> Hi there, > > I wondered if anybody had any experience with having nested > controllers?For example, I''d like a hierarchy something like this: > > /product > /product/list > /product/detail > /product/detail/category > > I can''t find any documentation on this, so any advice/experience > anybody might have would prove useful. > > N.B. This is for a generator which builds Views and Controllers from > a hierarchy held in a DB, so I need something which will be flexible > and anonymous. >AFAIK, you cannot do this with rails at this point. The reason is that the controller that will be matched will be the first one that matches. So for example if you have, ProductController (/product) Product::ListController (/product/list) Product::DetailController (/product/detail) Product:::Detail::CategoryController (/product/detail/category) If you try /product/detail/category, rails will call :controller=>ProductController, :action=>detail, :id=>category. I raised this problem up before with David (see bug http://dev.rubyonrails.com/ticket/1375) but he said it would break current software. Not sure what current software because it doesn''t work with current base routing anyway. BTW, the patch was for 0.12.1 and does not apply anymore. Of course, ProductController Admin::ProductController will work correctly. /admin/product/ will call the right controller, but if you also have AdminController, well, then Admin::ProductController will never be called. Anyway, soon I''ll try to get something like this working with the Named Routes added in 0.13.x... Haven''t yet investigated that route. - Adam