4 ms·
One thing I can't figure out is whether to place my service objects under `/app/models` or under `/lib`. There doesn't seem to be a clear consensus on this? I t
by troels 13y ago
One thing I can't figure out is whether to place my service objects under `/app/models` or under `/lib`. There doesn't seem to be a clear consensus on this? I tend more towards the former, because autoload works better during development. Also, I consider them part of my domain model. What do you do?
- lengarvey 13y agoThere's nothing stopping you from creating extra folders under /app to contain various types of service objects. Personally I have: /app/factories - for classes which create active record objects /app/services - for classes which do something I generally don't care about the return value of. Often perfect for background jobs. /app/decorators - most of these are Draper classes /app/forms - form objects and a few others from various other gems.
- bphogan 13y agoI have app/services and just add that in application.rb to the load path.
- te_chris 13y agoYou don't even need to add that to the load path as of rails 4 - we have app/validators, app/services, app/forms, app/inputs etc etc, all autoloaded with no config.
- Legion 13y ago/app/interactors It's a trivial thing to add new folders like this to autoloading: # add to application.rb config.autoload_paths += %W(#{config.root}/app/interactors)
- nthj 13y agoAs of Rails 3.0, I believe app/anything/ is autoloaded: * https://github.com/rails/rails/blob/3-0-stable/railties/test/application/initializers/load_path_test.rb#L43 https://github.com/rails/rails/blob/3-0-stable/railties/test... * http://hakunin.com/rails3-load-paths http://hakunin.com/rails3-load-paths
- tomblomfield 13y agoAnything that is application-specific, we put in /app Anything that's generic and re-usable, we put in /lib. This code is normally a prime candidate for gems - only very simple code stays in /lib for very long.
- rjspotter 13y agoI use /app/interactors or /use_cases (per some Uncle Bob talk about architecture). I don't consider them models in the 'Data Model' sense so I don't put them in /app/models