ruby - Rails - Where (directories) to put Models that are not Active Record -
we building out apps have models not database components. curious learn others doing in rails community address subject.
we struggling put them.
should have:
app/models/domain or
app/domain/models or perhaps
app/models # business models app/models/ar # active record models or perhaps
app/models/domain/ # business models app/models/domain/ar # active record models part of struggling how close to rails standards , how create structure need.
if think of objects service objects, have
app/models/service-object and
app/models/ # plain active record another route go down not have stuff within app, e.g.
/service_objects instead of
/app/models/service_objects presumably if want access via rails app we're better of using app/ in order take advantage of convention on configuration.
in experience, division of put these models comes down functionally represent in specific context of application.
i reserve app/models resource based models. if model represents resource instantiated , manipulated application goes here. doesn't need ar or db backed.
if model serves consistent functionality varies on parameters, give them top level dir in app. such app/mailers app/observers etc. however, if have 1 resource requires observer, might not make sense have app/observers dir 1 file in it.
everything else goes in lib. there few reasons why preferable.
you can choose when require files in
lib. can more selective files loaded when app starts. if put inapp/modelsyou've got no granularity on gets loaded.namespacing models app grows easier in lib. sure can namespace in
app/modelsseveral layers of nesting inapp/modelsends nasty. it's best keep namespacing inlib.housekeeping made easier when you've got things in functionally correct place. it's not resource? it's not observer? must in
lib. whole reason you're putting thought front provide discoverability developers down line.
Comments
Post a Comment