0

So I'm building a Github based application with octokit and the rails api, I have the basic idea of what I want to do, but I'm not too sure where to do it. Is it better to manipulate fetched data in the model or in the controller, any help would be appreciated! Thanks ya'll.

iandeejay
  • 31
  • 5

1 Answers1

1

I've found the best way to figure out a question like that is imagine that you were writing an statless, UI less API for the application that was going to be called by various different clients, like a web service.

If the "manipulation" has to do with presentation in some UI of the objects represented by the models, then that sounds like controller. If its a "behavioral" feature of the objects themselves, or the type of manipulation that would be useful no matter what the presentation (for example a list of objects in some useful order based on the model properties) than I like to put that kind of thing in the model.

Hope that is somewhat helpful.

GGizmos
  • 3,443
  • 4
  • 27
  • 72
  • It is a lot helpful actually. Let me explain that the data I'm fetching I want to save in the database. I realize this code could expand fairly quick and they say skinny controllers - but is there really no way around this? And I suppose I'm not necessarily acting on the object, but saving data to the object. So that's why I'm as unsure as I am. – iandeejay May 02 '14 at 10:38
  • Well, how 'skinny' your controllers are just depends on how complicated user interactions you want to handle. If you are doing on basic CRUD operations, the controllers can be pretty skinny, just collecting user input from the form and updating the model and vice versa. The point is to just keep the logic that relates to the objects themselves out of the controllers, and let the controllers just 'mediate' between consumers of your app (user via forms, other applications via XML, API's etc.) For example, validations should be done on the model, not in the controllers. – GGizmos May 02 '14 at 16:26