Rails 4将类与模块混淆

时间:2014-04-27 13:15:52

标签: ruby-on-rails class module

我的模型定义为:

class Phaxio

require 'rest_client'
require 'json'

attr_accessor :api_key, :secret_key, :callback_url, :current_intranet

def initialize(args)
    @current_intranet = args.fetch(:current_intranet)

    if Rails.env.production?
        @api_key      = current_intranet.settings.find_first_by_group_type_name("phaxio","api_key").try(:value)
        @secret_key   = current_intranet.settings.find_first_by_group_type_name("phaxio","api_secret").try(:value)
        @callback_url = "http://www.production.com/phaxio_holla_back"
    else
        @api_key      = current_intranet.settings.find_first_by_group_type_name("phaxio","api_key_test").try(:value)
        @secret_key   = current_intranet.settings.find_first_by_group_type_name("phaxio","api_secret_test").try(:value)
        @callback_url = "http://development.com:3002/phaxio_holla_back"
    end
end

没有pha​​xio(或phaxios)表。该模型被命名为“phaxio.rb”。我没有pha​​xios_controller。

当我调用Phaxio.new(current_intranet)时,我得到了“未定义的方法`new for Phaxio:Module”。我没有Phaxio模块,我在我的应用程序上做了一个grep(它非常大),以确保“Phaxio”没有在其他地方定义。我有什么想法吗?

不,该应用程序未命名为“Phaxio”。我的application.rb是:

require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(:default, Rails.env)
module V2
   class Application < Rails::Application
      config.autoload_paths += Dir["#{config.root}/app/presenters/*"].find_all { |f| File.stat(f).directory? }
      config.autoload_paths += Dir["#{config.root}/app/services/*"].find_all { |f| File.stat(f).directory? }
      config.autoload_paths += Dir["#{config.root}/app/queries/*"].find_all { |f| File.stat(f).directory? }
      config.autoload_paths += Dir["#{config.root}/lib/*"].find_all { |f| File.stat(f).directory? }
      config.autoload_paths += %W(#{config.root}/lib)

      $TECH_EMAIL     = ["fhock@production.com", "wprince@production.com"]

      config.to_prepare do
         Devise::SessionsController.layout "sessions"
         #Devise::RegistrationsController.layout "sessions"
         #Devise::ConfirmationsController.layout "sessions"
         #Devise::UnlocksController.layout "sessions"            
         Devise::PasswordsController.layout "sessions"
      end
   end
end

require 'tools'
require 'pdf_tools'

1 个答案:

答案 0 :(得分:0)

在朋友的最后建议中,我将所有对phaxio的引用重命名为phaxio2,一切都很顺利。不知道为什么这会产生影响,因为我运行了一个grep来查找“phaxio”这个词的所有实例,以防有一些冲突的模块,但没有找到。我想有时候抓住吸管会起作用!