Joshua Muheim
2007-Apr-03 12:41 UTC
Admin::Contr does not use layouts/admin/application.rhtml!
Hi all I know that Rails uses the layout views/layouts/application.rhtml as default when not specified differently. But why do controllers in modules not also use their own application.rhtml? controllers/MyController => uses views/layouts/application.rhtml controllers/admin/MyController => also uses views/layouts/application.rhtml, but I''d like it to use uses views/admin/layouts/application.rhtml! Is this a bug or just a neglection in the specification of Rails? Greetz Josh -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mohit Sindhwani
2007-Apr-03 12:55 UTC
Re: Admin::Contr does not use layouts/admin/application.rhtml!
Joshua Muheim wrote:> Hi all > > I know that Rails uses the layout views/layouts/application.rhtml as > default when not specified differently. > But why do controllers in modules not also use their own > application.rhtml? > > controllers/MyController => uses views/layouts/application.rhtml > controllers/admin/MyController => also uses > views/layouts/application.rhtml, but I''d like it to use uses > views/admin/layouts/application.rhtml! > > Is this a bug or just a neglection in the specification of Rails? > > Greetz > Josh > >Reading this might help you: http://www.microisv.com.ph/blog/layout-tips-using-ruby-on-rails.html Cheers Mohit. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Joshua Muheim
2007-Apr-03 16:07 UTC
Re: Admin::Contr does not use layouts/admin/application.rhtm
Thanks, but that''s all familiar to me. My question is a different one: Why does MyModule/MyController use layouts/application.rhtml as layout and not layouts/my_module/application.rhtml? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Florian Gilcher
2007-Apr-03 17:17 UTC
Re: Admin::Contr does not use layouts/admin/application.rhtm
If the layout is not set explicitly, and the default layout for the controller is not present, the parents layout is chosen. Default layouts are chosen by controller name. As the parent of MyModule::Testcontroller is ::ApplicationController (without module), the path to the parents layout is /application.rhtml and not my_module/application.rhml (because ApplicationController itself has no module). This is not a bug. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Joshua Muheim
2007-Apr-03 17:45 UTC
Re: Admin::Contr does not use layouts/admin/application.rhtm
Florian Gilcher wrote:> If the layout is not set explicitly, and the default layout for the > controller is not present, the parents layout is chosen. Default layouts > are chosen by controller name. > > As the parent of MyModule::Testcontroller is ::ApplicationController > (without module), the path to the parents layout is /application.rhtml > and not my_module/application.rhml (because ApplicationController itself > has no module). > > This is not a bug.Thanks a lot, this sounds very reasonable. I created now a file controllers/admin/application.rb with the following content: class Admin::ApplicationController < ApplicationController end Although I require it in controllers/application.rb it seems not to be existend because when trying to extend my Admin::CountryController from Admin::ApplicationController I get the following error: uninitialized constant Admin::ApplicationController Anybody can help me? Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You should probably renamed your controller file to app/controllers/admin/application_controller.rb By default a user-defined controller named MyController would look for a file my_controller.rb Note the appended _controller, as only the default application controller looks for app/controllers/application.rb. Since your Admin::ApplicationController is user-defined, it has to look for app/controllers/admin/application_controller.rb instead. I hope this helps. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Please scrap my last reply. I think you want to use your admin/application.rb layout in all admin controllers, so here''s what you should put in your Admin::ApplicationController class instead: class Admin::ApplicationController < ApplicationController layout ''admin/application.rb'' end If you call: class Admin::MyController < Admin::ApplicationController end it will use the admin/application.rb layout -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Joshua Muheim
2007-Apr-07 08:42 UTC
Re: Admin::Contr does not use layouts/admin/application.rhtm
> class Admin::ApplicationController < ApplicationController > layout ''admin/application.rb'' > endThank you! I didn''t even need the layout() call, it used the admin/layouts/application.rhtml automatically. :-) Now my only question is: how can I prevent somebody from calling /admin/application (which loads admin/application_controller.rb)? I want it to result in a routing error like when calling /application (which does *not* load application.rb)... Thanks a lot for help -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Joshua Muheim
2007-Apr-07 09:23 UTC
Re: Admin::Contr does not use layouts/admin/application.rhtm
Well, I just renamed the file admin/application_controller.rb to admin/application.rb and now I get the desired routing error when calling admin/application But sadly I have to add the line require File.dirname(__FILE__) + ''/application'' to every controller in the Admin module. I''d like Rails to search for a file application.rb in every Module and to load it if available (like it does with the default application.rb file). Is there a way to accomplish this? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Joshua Muheim
2007-Apr-07 09:29 UTC
Re: Admin::Contr does not use layouts/admin/application.rhtm
Well, I just placed the definition of Admin::ApplicationController into the controllers/application.rb file. Problem solved. :-P Why do it easily if there''s a more complicated way? ;-) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---