If you are looking up documentation about the Jobs functionality within Rails you can occasionally see that the sample Jobs class appears to inherit from two different classes.

Some examples will show something like;

class MyJob < ActiveJob::Base

Whilst others will be more like;

class MyJob < ApplicationJob

When you create a new Rails 5 project a file is created within app/jobs called application_job.rb and in it we create a class called ApplicationJob which inherits from ActiveJob::Base.

class ApplicationJob < ActiveJob::Base

The chances are if you’re reading a guide that mentions ApplicationJob then it was created assuming a Rails 5 starting point, guides or sample code mentioning ActiveJob::Base are ones that don’t assume you have the application_job.rb file.

Best practice is to use ApplicationJob and create the empty class if you don’t have one already – this will allow you to add code which can be inherited by all of your Jobs.

Why not read some more of our Ruby posts?