---
title: "Rails 5 adds another base class Application Job for jobs"
description: "Rails 5 adds explicit base class ApplicationJob for ActiveJob."
canonical_url: "https://www.bigbinary.com/blog/rails-5-adds-application-jobs-for-jobs"
markdown_url: "https://www.bigbinary.com/blog/rails-5-adds-application-jobs-for-jobs.md"
---

# Rails 5 adds another base class Application Job for jobs

Rails 5 adds explicit base class ApplicationJob for ActiveJob.

- Author: Hitesh Rawal
- Published: June 12, 2016
- Categories: Rails 5, Rails

Rails 5 has added another base class
[ApplicationJob](https://github.com/rails/rails/pull/19034) which inherits from
`ActiveJob::Base`. Now by default all new Rails 5 applications will have
`application_job.rb`.

```ruby
# app/jobs/application_job.rb
class ApplicationJob < ActiveJob::Base
end
```

In Rails 4.x if we want to use
[ActiveJob](http://guides.rubyonrails.org/active_job_basics.html) then first we
need to generate a job and all the generated jobs directly inherit from
`ActiveJob::Base`.

```ruby
# app/jobs/guests_cleanup_job.rb
class GuestsCleanupJob < ActiveJob::Base
  queue_as :default

  def perform(*guests)
    # Do something later
  end
end
```

Rails 5 adds explicit base class `ApplicationJob` for `ActiveJob`. As you can
see this is not a big change but it is a good change in terms of being
consistent with how controllers have `ApplicationController` and models have
[ApplicationRecord](application-record-in-rails-5).

Now `ApplicationJob` will be a single place to apply all kind of customizations
and extensions needed for an application, instead of applying patch on
`ActiveJob::Base`.

## Upgrading from Rails 4.x

When upgrading from Rails 4.x to Rails 5 we need to create `application_job.rb`
file in `app/jobs/` and add the following content.

```ruby
# app/jobs/application_job.rb
class ApplicationJob < ActiveJob::Base
end
```

We also need to change all the existing job classes to inherit from
`ApplicationJob` instead of `ActiveJob::Base`.

Here is the revised code of `GuestCleanupJob` class.

```ruby
# app/jobs/guests_cleanup_job.rb
class GuestsCleanupJob < ApplicationJob
  queue_as :default

  def perform(*guests)
    # Do something later
  end
end
```

## Links

- [Human page](https://www.bigbinary.com/blog/rails-5-adds-application-jobs-for-jobs)
