Rails 4.2 - Created a "services" directory for the PORO helpers, but the console / controllers etc. Doesn't see him

I have some logic that will manipulate the data before starting the job queue. However, inside the controller as well as in the rails console, I cannot access the classes. Example:

As app/services/hobo_service.rb

I have

class HoboService
  def initialize
    @api = Hobos::Api.new
  end

  def run
    hobo
  end

  private

  attr_reader :api

  def hobo
    api.hobo
  end
end

      

However, if in my relevant controller I put

...
  def create
    @name = HoboService.new.run
  end
...

      

Throws an exception saying the object could not be found.

It seems like everything in the directory app

should be in a pipeline and accessible. What am I missing here? Since then, until recently, there hasn't been with Rails.

+3


source to share


1 answer


I'm not sure why the application subdirectory will be ignored, but try a simple solution. What happens if you add it to the Application class in your application.rb application?



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

+1


source







All Articles