From: John Joyce Date: 2007-05-01T13:39:03+09:00 Subject: Re: Problem with RoR's controller getting too large On Apr 30, 2007, at 10:05 PM, shurain wrote: > Let's assume that there are two models Post and Comment. If we have a > controller dealing with both of these models, it wouldn't take long > before the controller grows too big to maintain. As far as I > understand, this happens because a controller tries to handle all the > actions allowed by the user. If I change the perspective and create a > controller per model the controller getting too large is fixed but I > have another problem. > > I don't see any good way of accessing multiple controllers (or models) > in one view. There are times when I have to see an instance of a Post > "AND" the comments which belongs to the post. I've heard that it can > be solved by using components but that has been deprecated and I've > heard that there are some issues which discourage its use. Using > application.rb doesn't really help because it still makes the > controller grow large. Is there any clean solution to this? For what it's worth, this case is easily a Ruby question too. Take a Ruby angle not so much a Rails angle on this. You need to separate out some of the functionality of your controllers. Clearly they can both inherit common functions (methods) from a parent class or from a module of some kind. It really is a matter of that. It is a design issue. As for a class or set of classes (controller) growing large... this is software. Every piece of functionality added will increase complexity almost exponentially. It does become more difficult to manage it mentally. That's what documentation and notes are for. Pen and paper become very nice tools at this point. Draw little diagrams and illustrate your design somewhat. The Ruby way is generally pretty good at keeping things smallish and manageable, and thus, self- documenting to some degree, but at some point you can't avoid documentation and drawing.