design - General rules for detemining which models/controllers one needs when building a Rails app -
i rails newbie. had @ different tutorials , books. 1 common thing teach different aspects of rails following step-by-step guide on building simple app. shows how things. however, more interested in following question - if know app should in terms of features , does, how determine models/controllers need? mean, in tutorials tell you, example, build users model, posts model , comments model (if it's blog app), how know upfront need these models? there general rules when unit of application should become model vs. keeping part of existing model?
a brief example: want build enterprise voting app, each user can assigned 1 or more shareholders , take part in general meetings each meeting containing several agenda items, can vote on. o.k., need user model/controller, maybe shareholders model, meetings model , questions model, how figure out if need other models?
the quick answer there no general rules this.
it idea sit down pen , paper , sketch out application objects , functionality. you'll see objects need.
you user model/controller. agree, perhaps shareholder attribute on user model.
for instance can vote object it's own model. if want track agenda items votes , user have voted on.
vote model this
class vote belongs_to :user belongs_to :item end
only add controller actions need. vote model might not need controller. perhaps want add functionality need controller, statistics pages.
my point have plan want , know models , controllers need. planing real time saver!
Comments
Post a Comment