0

I'd like to add a microapp for errors to be processed (file I placed inside the lib folder).

module MyApp
  class Application < Rails::Application
    config.autoload_paths += %W( #{config.root}/lib )
    config.exceptions_app = FooApp.new(Rails.public_path)
  end
end

But Rails raises an unitialized constant (NameError) during it's initialization. Recently I found a similar post and tried every solution from there, but got no result. What actually I've tried:

  1. Name a class and a filename according to convention (even tried to simplify to a single word - class Foo, filename lib/foo.rb).
  2. Use config.eager_load_paths += %W( #{config.root}/lib ) rather than config.autoload_paths, same effect. :(
  3. Create an initializer file and load a class with require: require "#{Rails.root}/lib/foo" It doesn't work - seems initializers are performed after the initial Rails configuration.
  4. Move the file into app/misc but it doesn't help.
  5. Put a class inside a module with the same name, rename a class while it's still in the module - no effect.

The only working solution I found - is to require a file right inside the Rails configuration block, but... it's a freaky solution. Probably there still exists an idiomatic one?

Community
  • 1
  • 1
DreamWalker
  • 1,327
  • 1
  • 11
  • 19

0 Answers0