0

i have a rails 5 app and some of my directories in app/ dont autoload. how do i set the app to automatically load stuff in directories like:

app/workflows app/validators whether it be specs or a real server?

i tried:

config.autoload_paths << Rails.root.join('app/*') or config.autoload_paths << Rails.root.join('app/validators')

but it doesnt work. how can i just load every file in app/ directory?

EDIT

one of the classes that i need to have manually loaded in specs:

module Validator
  class Token < Base
    validate :date_correctness

    def initialize(decoded_auth_token: decoded_auth_token)
      @expiration_date = decoded_auth_token[:expiration_date]
    end

    private

    attr_reader :expiration_date

    def date_correctness
      return true if Date.parse(expiration_date) >= Date.today
      errors.add(:token, 'is expired')
    end
  end
end

app/validators/token.rb

Leo
  • 2,061
  • 4
  • 30
  • 58
  • You shouldn't have to set anything up. Your classes should autoload when they are in subdirectories of `app`. Can you show your code for one of the classes that doesn't load? – jvillian Oct 19 '18 at 23:48
  • This answer to a related question may help: https://stackoverflow.com/a/45357284/3784008 – anothermh Oct 20 '18 at 04:53

1 Answers1

0

Try something like this in application.rb

config.autoload_paths += Dir[Rails.root.join('app', 'workflows', '{*/}')]
config.autoload_paths += Dir[Rails.root.join('app', 'validators', '{*/}')]
lacostenycoder
  • 10,623
  • 4
  • 31
  • 48