Hey all, Ok this is probably a newb question, but I haven''t been programming with MVC for very long, and I''ve been wondering what the general opinion is, or best practices, for making a new controller. Like what cases would you need a new controller for and what cases can you just put everything into one controller? Thanks in advance, Randal -- Posted via http://www.ruby-forum.com/.
Randal, It really depends on your preferences.. I tend to design controllers around "units of functionality". I find that if I have one controller juggling too many models, the code becomes cluttered.. For example, I could end up with a blogging controller that has list(), list_articles() when it could be simply split up amongst 2 controllers: controller1.list(), controller2.list(). The added benefit is that it''s much easier to work with the scaffolding than to fight it.. :) Please be advised that I am not an expert in this area ilan Randal Santia wrote:> Hey all, > > Ok this is probably a newb question, but I haven''t been programming with > MVC for very long, and I''ve been wondering what the general opinion is, > or best practices, for making a new controller. Like what cases would > you need a new controller for and what cases can you just put everything > into one controller? > > Thanks in advance, > Randal-- Posted via http://www.ruby-forum.com/.
If you''re just starting out, keep it simple and create a separate controller for each use case in your application. Randal Santia wrote:> Hey all, > > Ok this is probably a newb question, but I haven''t been programming with > MVC for very long, and I''ve been wondering what the general opinion is, > or best practices, for making a new controller. Like what cases would > you need a new controller for and what cases can you just put everything > into one controller? > > Thanks in advance, > Randal-- Posted via http://www.ruby-forum.com/.
Be careful here... you don''t want to confuse controller''s with their actions. Controllers are a way to group user-focused functionality, but unless you are designing extremely broad use cases, each of your apps controllers will likely impact far more than a single use case. Since people like to use the "blog app" example, I would recommend downloading the Typo source code and looking at how the Controllers and Models are laid out in there. It''s a pretty good balance, with probably a few more controllers than is actually needed (not counting the admin stuff, since admin interfaces are very different from user interfaces), but still a very good organization example. -Brian On May 1, 2006, at 04:58 PM, Mick Sharpe wrote:> If you''re just starting out, keep it simple and create a separate > controller for each use case in your application. > > Randal Santia wrote: >> Ok this is probably a newb question, but I haven''t been >> programming with >> MVC for very long, and I''ve been wondering what the general >> opinion is, >> or best practices, for making a new controller. Like what cases >> would >> you need a new controller for and what cases can you just put >> everything >> into one controller?
Thanks guys. I''ll keep that in mind! Mick Sharpe wrote:> If you''re just starting out, keep it simple and create a separate > controller for each use case in your application. > > Randal Santia wrote: >> Hey all, >> >> Ok this is probably a newb question, but I haven''t been programming with >> MVC for very long, and I''ve been wondering what the general opinion is, >> or best practices, for making a new controller. Like what cases would >> you need a new controller for and what cases can you just put everything >> into one controller? >> >> Thanks in advance, >> Randal-- Posted via http://www.ruby-forum.com/.