Joshua Muheim
2006-Dec-10 21:33 UTC
model-controller-paradigm: What about admin controllers?
Hi all We all know the model-controller-paradigm: I have a model "News" which has a corresponding CRUD-controller "NewsController". But now I''m quite unsure about the following... Guess we have normal visitors that visit our site www.??.com/news and we have administrators that create and modify news items. The admin should see an "Edit" link and a "Destroy" link corresponding to every news item, but visitors should not see them. So we mix some admin functions into the views. Further on we need some methods like www.??.com/news/edit/:id that should only be callable by an admin; we can easily secure this using a before_filter or so. So far so good. But the more complex our model becomes, the more we have to mix admin logic with visitor logic. So I guess it would be cleaner if we created not only one corresponding controller, but two of them: a NewsController that is an interface between data and visitors and a NewsAdminController that handles all the CRUD-and-more stuff an admin can do. Is this a good solution? I could then create a route that sends URL calls like www.??.com/news to the NewsController and URL calls like www.??.com/admin/news to the NewsAdminController... Please tell me what you think about this. Are there better solutions for separating user logic and admin logic? Thanks for your interesting answers, Joshua -- 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 -~----------~----~----~----~------~----~------~--~---
alot of ppl are torn by this very issue. Personally, i find it easier to give the extra namespace by adding afolder called admins/ in the app directory and put all the admin functionality in there. It just looks nicer. Im sure there are plenty of reasons this is wrong (REST and stuff like that), but i really dont care. It just ''feels'' easier. peace --jake Joshua Muheim wrote:> Hi all > > We all know the model-controller-paradigm: I have a model "News" which > has a corresponding CRUD-controller "NewsController". > > But now I''m quite unsure about the following... > > Guess we have normal visitors that visit our site www.??.com/news and we > have administrators that create and modify news items. > The admin should see an "Edit" link and a "Destroy" link corresponding > to every news item, but visitors should not see them. So we mix some > admin functions into the views. > Further on we need some methods like www.??.com/news/edit/:id that > should only be callable by an admin; we can easily secure this using a > before_filter or so. > > So far so good. But the more complex our model becomes, the more we have > to mix admin logic with visitor logic. > So I guess it would be cleaner if we created not only one corresponding > controller, but two of them: a NewsController that is an interface > between data and visitors and a NewsAdminController that handles all the > CRUD-and-more stuff an admin can do. > Is this a good solution? I could then create a route that sends URL > calls like www.??.com/news to the NewsController and URL calls like > www.??.com/admin/news to the NewsAdminController... > > Please tell me what you think about this. Are there better solutions for > separating user logic and admin logic? > > Thanks for your interesting answers, > Joshua-- 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
2006-Dec-11 21:54 UTC
Re: model-controller-paradigm: What about admin controllers?
jake wrote:> alot of ppl are torn by this very issue. Personally, i find it easier > to give the extra namespace by adding afolder called admins/ in the app > directory and put all the admin functionality in there. It just looks > nicer. > > Im sure there are plenty of reasons this is wrong (REST and stuff like > that), but i really dont care. It just ''feels'' easier.What exactly do you mean with REST? And are the controllers all found in this subfolder, or do you have to add it to the path? -- 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 -~----------~----~----~----~------~----~------~--~---
Jake Varghese
2006-Dec-13 23:03 UTC
Re: model-controller-paradigm: What about admin controllers?
Joshua Muheim wrote:> jake wrote: >> alot of ppl are torn by this very issue. Personally, i find it easier >> to give the extra namespace by adding afolder called admins/ in the app >> directory and put all the admin functionality in there. It just looks >> nicer. >> >> Im sure there are plenty of reasons this is wrong (REST and stuff like >> that), but i really dont care. It just ''feels'' easier. > > What exactly do you mean with REST? And are the controllers all found in > this subfolder, or do you have to add it to the path?REST (or Representational State Transfer) is a paradigm of software design. Check it out at: http://en.wikipedia.org/wiki/Representational_State_Transfer. Only the editing part of the models is done in the admin controllers. Outside of the admin controllers are the public facing. For example: app/ --admin/ ----posts_controller.rb <= for administration ----comments_controller.rb --post_controller.rb <= public facing --comments controller --jake -- 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
2006-Dec-16 11:12 UTC
Re: model-controller-paradigm: What about admin controllers?
> app/ > --admin/ > ----posts_controller.rb <= for administration > ----comments_controller.rb > --post_controller.rb <= public facing > --comments controllerSo they are called like this? PostsAdminController CommentsAdminController PostsController AdminController Right? Is there no problem for Rails to find the admin controllers? Do I have to adjust the path var or something? -- 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 -~----------~----~----~----~------~----~------~--~---
Jake Varghese
2006-Dec-16 17:13 UTC
Re: model-controller-paradigm: What about admin controllers?
Joshua Muheim wrote:>> app/ >> --admin/ >> ----posts_controller.rb <= for administration >> ----comments_controller.rb >> --post_controller.rb <= public facing >> --comments controller > > So they are called like this? > > PostsAdminController > CommentsAdminController > PostsController > AdminController > > Right? Is there no problem for Rails to find the admin controllers? Do I > have to adjust the path var or something?actually, they are called Admin::PostsController Admin::CommentsController PostsController CommentsController so, when you do a link_to to the admin section you would use: link_to "Link Me", :controller => "admin/posts", :action => "edit_post", :id => 1 Most of the time, you will never do the above because you usually dont want to link from the public facing side to the admin side. --jake -- 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 -~----------~----~----~----~------~----~------~--~---