0

我正在尝试在 Rails 中重新打开一个来自引擎的类。我做了以下事情:

module Xaaron
  ApiKey.class_eval do
     include Promiscuous::Publisher
     publish :xaaron_users_id, :api_key, :as => :ApiKey
  end
end

它位于:

  models/
    Xaaron/
      api_key.rb

这一切都在我的应用程序中,然后应该让我运行:

bundle exec promiscuous publish "Xaaron::ApiKey.all"

但是,当我这样做时,我得到了错误:

RuntimeError: Circular dependency detected while autoloading constant Xaaron::ApiKey
4

2 回答 2

1

TL;DR: Try renaming api_key.rb to something else.

Here is what I think is happening: Rails autoloader loads Xaaron/api_key.rb and encounters an unknown constant Xaaron::ApiKey. It then tries to load it from file called (based on constant name)... Xaaron/api_key.rb. Boom, circular dependency.

于 2014-07-02T13:05:31.190 回答
0

就像@artemave 所说,重命名文件。如果这不起作用,请尝试:

Xaaron::ApiKey.class_eval do
于 2017-01-26T21:26:33.563 回答