My question is about where certain kinds of logic sit in the Model and
Controller objects or more specifically the relationship between Model
Does an Model class contain a Controller class, the otherway round, or
are they two seperate classes that talk?
I’m fairly new to RoR, but this is my understanding of how it works
(someone please correct me if I’m wrong):
The model should be fairly self-contained, rarely communicating to
external objects. This also means that it should not communicate
directly with the controller nor should it even know one exists.
Often the model parallels a table in a database: the class being the
table, the objects (instances of the class) being rows in that table,
and the object’s attributes being columns in the table.
To put it short, the model only messes with it’s own stuff and no one
else’s. The primary exception to this is if the model is related to
other models (such as with has_many) then it can communicate with the
related models too.
The controller, on the other hand, often sends messages to many
different models - retrieving the model objects to prepare for
displaying them in the view. However, be on the lookout for code in
the controller that just messes with the model. This should be
refactored (moved) into the model so the controller can be simpler
and other controllers can use that code.
Hope that made sense and answered your question.