获得“未初始化的常数".尝试在Rails中调用我的服务时 [英] Getting "uninitialized constant" when trying to invoke my service in Rails

查看:121
本文介绍了获得“未初始化的常数".尝试在Rails中调用我的服务时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 4.2.3.我在控制器中有这行:

I'm using Rails 4.2.3. I have this line in a controller:

service = XACTEService.new("Event", '2015-06-01', 'Zoo')

所涉及的类在app/services/XACTEService.rb中定义.但是,在访问我的控制器时,出现错误:

The class in question is defined in app/services/XACTEService.rb. However upon visiting my controller, I get the error:

uninitialized constant MyObjectsController::XACTEService

但是,我已将其添加到config/application.rb文件中

However, I have added this into my config/application.rb file

  class Application < Rails::Application
    config.autoload_paths += %W(#{config.root}/services)

所以我不明白为什么控制器无法找到我的服务.

So I don’t understand why the controller is failing to find my service.

推荐答案

重命名此文件:

app/services/XACTEService.rb

收件人:

app/services/xacte_service.rb

这篇关于获得“未初始化的常数".尝试在Rails中调用我的服务时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆