简体   繁体   English

控制器模块中的未初始化常量

[英]Uninitialized constant in module in controller

I have this controller 我有这个控制器

  module GaReporting
    module Api

      class GaGatheringController < ApplicationController
        client = Google::APIClient.new(...)
      end
    end
  end

However I get an uninitialized constant error for the uninitialized constant GaReporting::Api::GaGatheringController::Google 但是我得到未uninitialized constant GaReporting::Api::GaGatheringController::Google的未初始化常量错误

This is curious since this line works fine when I just call it in a "normal" controller that is not inside any modules. 这很好奇,因为当我在没有任何模块内部的“普通”控制器中调用该行时,该行工作正常。

How do I fix this and why is it not working? 如何解决此问题,为什么不起作用?

adding require 'google/api_client' in the class does the trick. class中添加require 'google/api_client'可以解决问题。 Interesting that in the module the require statement is -- pardon the pun -- required since in a regular controller it is not. 有趣的是,在模块中, require语句是必需的(请双关语),因为在常规控制器中不需要。

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

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