Getting “uninitialized constant” when trying to invoke my service in Rails

巧了我就是萌 提交于 2019-12-10 10:55:46

问题


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

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

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

uninitialized constant MyObjectsController::XACTEService

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.


回答1:


Rename this file:

app/services/XACTEService.rb

to:

app/services/xacte_service.rb


来源:https://stackoverflow.com/questions/37547441/getting-uninitialized-constant-when-trying-to-invoke-my-service-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!