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.

  1. you can choose when require files in lib. can more selective files loaded when app starts. if put in app/models you've got no granularity on gets loaded.

  2. namespacing models app grows easier in lib. sure can namespace in app/models several layers of nesting in app/models ends nasty. it's best keep namespacing in lib.

  3. 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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -