rails: Rails 4.2.0.beta2 LOAD_PATH no longer includes lib in config/application.rb boot

This may be an intentional or expected change in Rails 4.2, but I hadn’t seen it mentioned anywhere, so am reporting it.

In Rails 4.1.6, at the point your < Rails::Application class is loaded, the ruby $LOAD_PATH has already been set to include the local application’s ./lib directory.

In Rails 4.2.0.beta2, it has not been.

My use case is that I have a custom LogFormatter in my application’s ./lib. I want to set it in my ./config/application.rb, using config.log_formatter =.

# ./config/application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module MyApp
  class Application < Rails::Application

    require 'my_custom_log_formatter'
    config.log_formatter = MyCustomLogFormatter.new

    #.....
  end
end

Where the log formatter lives in ./lib/my_custom_log_formatter.rb.

In Rails 4.1.6, no problem. In Rails 4.2.0.beta2, config/application.rb:12:in 'require': cannot load such file -- my_custom_log_formatter (LoadError)

Exploring the $LOAD_PATH at this point in program execution, I confirm that in rails 4.1.6, the $LOAD_PATH included my application’s local ./lib at this point, in Rails 4.2.0.beta2 it does not.

There are a variety of workarounds, including adding it to the $LOAD_PATH myself, or setting the log_formatter at some other point in the startup process (but if you do it too late, I believe it has no effect, is why I was doing it in ./config/application.rb after confirming that’s not too late).

Reporting in case it’s not intentional and is considered a regression.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 18 (18 by maintainers)

Commits related to this issue

Most upvoted comments

@jrochkind @tenderlove : Thanks you very much guys! 😃