Reputation: 49067
If I understand MVC correctly Controllers should only contain logic that glue the model together with the view. It contains the application logic such as authentication, session and other things for the application. The model on the other hand should do the business logic of the application and the views should update in response to changes on the model. However, how do you this in Rails?
My controllers contain logic that finds model objects etc and then update the views in response.
Have I misunderstood application logic and business logic. I would apprciate if somebody could help me understand MVC.
Upvotes: 2
Views: 448
Reputation: 12341
Part of the problem is that the Rails architecture makes it look like model = ActiveRecord, and that's not necessarily true. A Model class or module can be anything you like.
When the models -are- ActiveRecord (which does make sense in the majority of cases), you can add methods to those classes that can be invoked by the controllers and that contain the business logic.
Upvotes: 2
Reputation: 132197
Rails is a good implementation of MVC and allows good abstractions. Finding model objects is not business logic.
To make sure you get this right, keep your controllers short; move any significant logic to models by creating new methods; use the built-in rails helpers and methods; follow RESTful architecture where possible (not perfect, but helps) and get someone else to discuss your code with you.
Upvotes: 3