Marcelo de Moraes Serpa
2007-Aug-30 17:48 UTC
Patterns for implementing "admin" functionality to rails'' models and controller "layouts"
Hello list, In my application, I''ve followed the following pattern - for each model, I have a correspondent controller. For example, I''ve got a Document mode, and a DocumentsController, a DocType model and DocTypesController and so on... Should I just put new admin actions into these controllers ? I''m not sure if the pattern I''ve followed for the controllers is the ideal one: * Maybe I should put these controllers into a admin subdir/module and create other controllers for other data access levels (not admin). * Maybe a model does not have to necessarily have a correspondent controller; * Maybe this way of thinking is limiting! So, any suggestions on how could I lay out my controllers and also the admin aspect of the application would be greatly appreciated! Thanks, Marcelo. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bob Showalter
2007-Aug-30 18:51 UTC
Re: Patterns for implementing "admin" functionality to rails'' models and controller "layouts"
On 8/30/07, Marcelo de Moraes Serpa <celoserpa-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello list, > > In my application, I''ve followed the following pattern - for each model, I > have a correspondent controller. For example, I''ve got a Document mode, and > a DocumentsController, a DocType model and DocTypesController and so on... > Should I just put new admin actions into these controllers ? > > I''m not sure if the pattern I''ve followed for the controllers is the ideal > one: > > * Maybe I should put these controllers into a admin subdir/module and > create other controllers for other data access levels (not admin). > * Maybe a model does not have to necessarily have a correspondent > controller; > * Maybe this way of thinking is limiting! > > So, any suggestions on how could I lay out my controllers and also the admin > aspect of the application would be greatly appreciated!I don''t recommend using nested controllers (controllers in subdirs below app/controllers). If you want nested url''s you can achieve that with routes. There does not have to be a 1-1 correspondence between models and controllers. You can put your admin actions in the same controller as the normal actions; it makes your before_filter specification a bit more complex. The nice thing about having a separate controller for admin actions is that you can use a catch-all before_filter to require admin login. You can even create an "abstract" admin controller with the before_filter and then have all your admin-specific controllers inherit from that one: class AdminController < ApplicationController before_filter :require_admin_login end class WidgetAdminController < AdminController ... end Then you could route (for example): /widget/:action/:id to WidgetController /admin/widget/:action/:id to WidgetAdminController You get the idea... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mark Thomas
2007-Aug-30 19:25 UTC
Re: Patterns for implementing "admin" functionality to rails'' models and controller "layouts"
I too have been creating nested admin controllers and thinking there had to be a better way.> class AdminController < ApplicationController > before_filter :require_admin_login > end > > class WidgetAdminController < AdminController > ... > endThis is an excellent idea.> Then you could route (for example): > > /widget/:action/:id to WidgetController > /admin/widget/:action/:id to WidgetAdminControllerThanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Marcelo de Moraes Serpa
2007-Aug-30 20:03 UTC
Re: Patterns for implementing "admin" functionality to rails'' models and controller "layouts"
Thanks for the tips Bob! So, if I understood, for each controller with "regular" actions that I would want admin functionality, I would create a correspondent admin controller? i.e DocumentController DocumentAdminController Thanks again, Marcelo. On 8/30/07, Mark Thomas <ruby-gkTqyYPWbQbz1n+OaKNE4w@public.gmane.org> wrote:> > > I too have been creating nested admin controllers and thinking there > had to be a better way. > > > class AdminController < ApplicationController > > before_filter :require_admin_login > > end > > > > class WidgetAdminController < AdminController > > ... > > end > > This is an excellent idea. > > > Then you could route (for example): > > > > /widget/:action/:id to WidgetController > > /admin/widget/:action/:id to WidgetAdminController > > Thanks! > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---