[英]'load_missing_constant' when trying to create an observer on Rails
I am trying to create an observer for my Offer
model but I keep getting this error: 我正在尝试为我的
Offer
模型创建一个观察者,但我不断收到此错误:
/Users/codus/.rvm/gems/ruby-1.9.3-p194@gyp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:503:in `load_missing_constant': Expected /Users/codus/Projetos/gyp-revolution/app/models/offer.rb to define Offer (LoadError)
There is nothing special about my model and I am sure it is declared in the right place (the application works fine without the observer). 我的模型没有什么特别的,并且我可以肯定它在正确的地方声明了(该应用程序在没有观察者的情况下也可以正常工作)。
I've generated my observer with the Rails script 我已经用Rails脚本生成了观察者
rails g observer offer
And I added this in my config/application.rb
file 并将其添加到我的
config/application.rb
文件中
config.active_record.observers = :offer_observer
The strangest part is that it works fine with all my other models. 最奇怪的是,它与我的所有其他模型都可以正常工作。
I am using Rails 3.2.6 with Ruby 1.9.3p194. 我正在将Rails 3.2.6与Ruby 1.9.3p194一起使用。
The problem was that I was using FactoryGirl, and inside my Offer
factory I called a constant defined in my model. 问题是我正在使用FactoryGirl,并且在我的
Offer
工厂内部,我调用了模型中定义的常量。 The factory was being loaded before the model, so this error was happening. 在模型之前已加载了工厂,因此发生了此错误。
It's weird that the observer changed this, it works fine without it. 观察者更改了它很奇怪,没有它就可以正常工作。 Now I just use the value in my factory, not the constant.
现在,我只在工厂中使用值,而不是常量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.