1

I have a rails API, I want to use the services globally without require them in the controllers.

Print off the "#{config.root}" shows "/Users/sorry/Projects/project_Api/Api_test"

Structure Api_test ----> app -----> services ------> services.rb

In "config/application.rb" I have tried many things. config.autoload_paths += ["#{config.root}/app/services/sales_flow_service.rb"] config.autoload_paths += ["#{config.root}/app/services"]

with a different structure. Api_test ----> app -----> lib ------> services.rb and Api_test ----> app -----> lib ------> services ----> services.rb config.autoload_paths += ["#{config.root}/app/lib"] config.autoload_paths += ["#{config.root}/app/lib/services/services.rb"]

For some reason it does not work. What am I missing? Thanks in advance

Hedu
  • 61
  • 4
  • what so you mean by not using in controllers ?? – Thorin May 17 '16 at 17:31
  • They are separately, but I call them from the controller. I need to require 'service.rb' I do not want to, I need them to be available everywhere, do u know what I mean? – Hedu May 17 '16 at 17:33
  • In recent versions of Rails, everything in `app` is autoloaded. What version of Rails is this? – Jim Van Fleet May 17 '16 at 19:29
  • the version is Rails 4.2.6, I am afraid it does not load it for some reason Jim :\ – Hedu May 17 '16 at 19:57
  • strange that it isn't working, might be how you are calling the classes or code from services.rb? – Agush May 17 '16 at 20:14
  • maybe take at look at this? http://stackoverflow.com/questions/9430097/how-to-autoload-files-in-folder-under-rails-apps-root – Agush May 17 '16 at 20:15
  • Agush, that was a really good post/information, thanks. – Hedu May 18 '16 at 17:37

0 Answers0