ActiveJob Vs ApplicationJob

A very quick clarification on ActiveJob and ApplicationJob

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
end

Whilst others will be more like;

class MyJob < ApplicationJob
end

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
end

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.

Recent posts View all

SEO

Google follows URLs in text

Today I learned that Google follows URLs even when they are plain text

Web Dev

Check in with your database

It pays to take a step back and look at how your database is set up every so often. You will often find quick wins and hidden tech debt.