简体   繁体   中英

uninitialized constant StartupsController::GraphUpdate

I'm attempting to create a custom class in Rails that will be triggered as a background task via Delayed Job whenever an action happens in the view. However, I'm getting an 'uninitialized constant StartupsController::GraphUpdate' error whenever I try to trigger the action.

Here's part of the controller code:

if request.patch?
  @startup_funding = StartupFunding.where(id: params[:id]).first
  if @startup_funding.update_attributes(startup_funding_round_params)
    redirect_to unique_names_path(@startup_funding.startup.unique_names.unique_name)
  end
  GraphUpdate.delay.update
end

Here's the custom class in the app/jobs directory:

class GraphUpdate < ActiveRecord::Base
  def update
    Rails.cache.fetch('x') {'test'}
  end
end

I'm not sure what went wrong here. This is the full trace: http://pastebin.com/qtaHghC8

Sounds like you might be on Rails 3. You need to add app/jobs to your autoload_paths:

# config/application.rb
config.autoload_paths += %W(#{config.root}/app/jobs)

Or just require your custom class in your controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM