简体   繁体   English

名称错误未初始化的常量模块导轨

[英]Name error uninitialized constant module rails

I have a rails application in that I have modules inside /app/adapters/UDB/ folder. 我有一个Rails应用程序,因为我在/app/adapters/UDB/文件夹中有模块。 The module is not loading. 该模块未加载。 I have added the following in application.rb 我在application.rb添加了以下内容

config.autoload_paths += Dir["#{config.root}/app/adapters/**/*"]

I am calling module from model file /models/userinvite.rb 我正在从模型文件/models/userinvite.rb调用模块

   def update_cassandra
    ypusers = UDB::YpRewards.new.ypusers
    ypusers.execute("UPDATE invitation_backlog SET invitation_code = '#{invitation_code}', invitation_sent_date = #{invitation_sent_date.to_i * 1000}, invited_by = '#{invited_by}' WHERE email_address = '#{email}'")
   end

/app/adapters/UDB/yp_rewards.rb /app/adapters/UDB/yp_rewards.rb

   module UDB
   class YpRewards
     def initialize

     end
     def ypusers
        @ypusers ||= UDB::Connection.new.connection.connect('ypusers')
     end
   ...

Please help me solving it. 请帮我解决。

I think the issue is with module name. 我认为问题出在模块名称上。

Your module name is UDB, then you can load this module by specifying its name in smallcase letters as per rails naming convention (camelcasing) 您的模块名称是UDB,然后您可以按照rails命名约定(大写)通过以小写字母指定其名称来加载该模块。

 config.autoload_paths += %W( #{config.root}/app/adapters/u_d_b)

Try including the module in your UserInvite model, 尝试将模块包含在UserInvite模型中,

include UDB

This is a good site to know more about the placement and usage of modules. 这是一个很好的站点,可以进一步了解模块的放置和使用情况。

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

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