This makes sure that the Rails application has loaded and all Ruby files are loaded: Rails.application.config.to_prepare do ... end