In an attempt to be more object-oriented, I find myself creating more POROs (Plain-old_ruby-objects). In rails, this simply means that the model class does not inherit from ActiveRecord::Base,
and thus this model is not backed by a database table.
Lets say I have an app with hundreds of models. It would be nice if there was some naming convention of PORO models so that those PORO models can be quickly identified instead of having to open up each of their files and notice that they do not inherit from ActiveRecord::Base
.
I could not find a naming convention for this. Does one exist in the rails community? If not, suggestions are welcome.
What I ended up doing was creating a subdirectory in my app/models
directory called: poros
.
In order to make those files within that poros
subdirectory available within the load path, I had to go into config/application.rb
and add this line:
config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')]
Now I can access those POROs just like I can with any of the Models.
I'm not aware of any naming convention for poro classes in the Rails community, even though there has been a recent trend to keep classes inheriting from ActiveRecord::Base
rather small.
If your classes are rather generic, they should be placed in the lib
directory. If they are specific to your app but only require no interaction with other classes, you could create service classes placed in app/services
. Similarly you can extract decorators, jobs and concerns.
Whatever classes remain can either stay in the app
folder, or be placed in a subdirectory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With