I am a Sr. Software Developer at Oracle Cloud. The opinions expressed here are my own and not necessarily those of my employer.
Rails concerns
By default Rails 4 and higher applications come with concerns in app/models/concerns/*
and app/controllers/concerns/*
. It can be a useful place to put code that needs to be shared across classes. It is also a way to implement multiple inheritance.
Here is one example:
There is no reason we need to limit this approach to only models and controllers. Perhaps there is common logic that we want to include in several jobs. We could place it in ApplicationJob
from which other Job classes inherit. Or we could put it in app/jobs/concerns/shared_job.job
and include that module in the specific jobs as needed.
Same can be done with other Ruby classes such as PORO service objects.
At the end of the day concerns
folder simply contains modules. Jobs, controllers, models are classes and we can just include a module in a class.