Business logic
Business logic
Unless your definition of model is the business logic area of your application. Saying that business logic goes in the model, in terms of the general rails sense, is the bad route.
I think there are two areas of confusion on the topic:
1. Web MVC isn't the same as the traditional MVC pattern as seen in apps and described in patterns literature. In the web version all communication between model and view is mediated through the controller layer and there is no direct control between them) - many web developers are only aware of this variant.
2. Rails popularised web MVC and used ActiveRecord which meant that models were essentially table wrappers and this pushed business object logic into the controller.
For me the next step after MVC is PAC - http://en.wikipedia.org/wiki/Presentation%E2%80%93abstractio... (which I think is pretty much the same thing as HMVC). Adding that extra dimension of multiple self-contained triads keeps the controller layer from becoming a single unwieldy mess of spaghetti spread across the whole web layer. (Ironically I suppose it does introduce a concept of events binding them which may bring it full circle to some ideas in the article.)
If, on the other hand, FooBarService has a handler for a MouseEvent - something that should be done in the Controller - and business logic in it too, now you're violating MVC because your Model and Controller aren't separated.
BTW, IMO to name something FooBarService or BazQuxService is a code smell. "Service" carries no significance. Same goes for "Manager" or "Logic" or whatever generic thing you end up using. Any code could be in there. I have to look inside it to see. It also gives you an excuse to make those file huge because anything could be in there. It's a violation of the Single Responsibility Principle.
Hah, yes, I'm a Java programmer.
Yes, that is the definition of the model in MVC.
Controller is just orchestrating the basket dance of the views and the model. Got this user input, fwd to this model, got this result from the model, wake this view.
Put another way, when business rules change, you change your models. When business behavior changes, you change your controllers.
If you add such rules in the controller, you have to split your rules in two places, which is bad.
Ideally, I always thought that business rules should be a kind of "config", or more accurately a set of files written in a mini-domain language, that would be readable by PMs. Then it would be the job of the model to interface this set of rules with the controller.
So no, business rules and logic and whatever do not belong to the controller.
Yes, 100% absolutely, no question.
>That fits into the class of behavior and belongs in a controller.
The controller is just to handle input, it has nothing to do with behavior. This is one of the key misunderstandings that differentiates between MVC and the weird mess rails calls MVC.
It has a very specific meaning: http://en.wikipedia.org/wiki/Model–view–controller
>At the same time, I also don't think such a rule belongs in your model layer.
I'm not talking personal preference, I am talking how MVC works. If your application were MVC, then yes it absolutely would be in the model.
Your actual procedural stuff that's actually deciding what to do to and with the data doesn't go in the database (stored proc fanboys be damned), and likewise doesn't go in the model.