简体   繁体   English

未初始化的常量StartupsController :: GraphUpdate

[英]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. 我试图在Rails中创建一个自定义类,每当视图中发生操作时,该类就会通过“延迟作业”作为后台任务触发。 However, I'm getting an 'uninitialized constant StartupsController::GraphUpdate' error whenever I try to trigger the action. 但是,每当我尝试触发该操作时,都会收到“未初始化的常量StartupsController :: GraphUpdate”错误。

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: 这是app / jobs目录中的自定义类:

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 这是完整的跟踪信息: http : //pastebin.com/qtaHghC8

Sounds like you might be on Rails 3. You need to add app/jobs to your autoload_paths: 听起来好像您在Rails 3上。您需要将app / jobs添加到autoload_paths中:

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

Or just require your custom class in your controller. 或者只需要在控制器中自定义类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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