Rails 4.1 with ActiveJob label - uninitialized ActiveJob constant

I followed getting started with active work from EngineYard. The article says:

You will need Rails 4.2.0beta1 or higher if you want the active job to be available by default (in older versions of Rails, you can require it as a gem)

I am trying to use ActiveJob in my Rails 4.1 project. I have added ActiveJob to my gemfile gem 'activejob'

. According to the article, I have:

#config/initializers/active_job.rb
ActiveJob::Base.queue_adapter = :resque

      

However, when I run rails server

I get the following error:

config/initializers/active_job.rb:1:in

': uninitialized ActiveJob constant (NameError) `

EDIT - Fixed table of contents "gem active job"

UPDATE 1

Following the below solution, adding require 'active_job'

to application.rb, I can no longer get the error uninitialized constant ActiveJob

, but instead I get an error undefined method perform_later'

when I try to call my job. I follow the rail guide and end up with code similar to:

MyJob.perform_later(record)

      

Start of my work class:

class MyJob < ActiveJob::Base
  queue_as :images
  def perform(id)

      

+3


source to share


3 answers


I found that the gem version of ActiveJob for rails 4.1 is 0, which is different from the version in Rails 4.2.

If you are using v0 ActiveJob the syntax should be:

MyJob.enqueue(record)

      



or

MyJob.enqueue(record, options)

      

You will find a lot of interesting things about ActiveJob with Rails 4.1 in this article: http://kinopyo.com/blog/use-activejob-in-rails-4-1/

+2


source


I added require 'active_job'

to config / application.rb just below all other directives and solved the problem for me.



+8


source


Use this gem if you want to use Active Job on Rails 4.0 or 4.1:

https://github.com/ankane/activejob_backport

But this gem is not pulled by Action Mailer, you need to stick with deliver

, see https://github.com/ankane/activejob_backport/issues/1 .

0


source







All Articles