ruby - Rails Model, View, Controller, and Helper: what goes where? -
in ruby on rails development (or mvc in general), quick rule should follow put logic.
please answer in affirmative - do put here, rather don't put there.
mvc
controller: put code here has working out user wants, , deciding give them, working out whether logged in, whether should see data, etc. in end, controller looks @ requests , works out data (models) show , views render. if in doubt whether code should go in controller, shouldn't. keep controllers skinny.
view: view should contain minimum code display data (model), shouldn't lots of processing or calculating, should displaying data calculated (or summarized) model, or generated controller. if view needs processing can't done model or controller, put code in helper. lots of ruby code in view makes pages markup hard read.
model: model should all code relates data (the entities make site e.g. users, post, accounts, friends etc.) lives. if code needs save, update or summarise data related entities, put here. re-usable across views , controllers.
Comments
Post a Comment