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

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -