Skip to content


Subversion checkout URL

You can clone with
Download ZIP


autoload HighVoltage::PageFinder to avoid uninitialized constant error #45

wants to merge 1 commit into from

6 participants


The following error raises every time after changing some files (or even just touching them, e.g., touch app/controllers/application_controller.rb) in my project and then visiting any static page without restarting the server:

NameError in HighVoltage::PagesController#show
uninitialized constant HighVoltage::PageFinder

I tried the following code in Rails console:

1.9.3p194 :002 > HighVoltage::PagesController
 => HighVoltage::PagesController 
1.9.3p194 :003 > HighVoltage::PageFinder
 => HighVoltage::PageFinder 
1.9.3p194 :004 > reload!
 => true 
1.9.3p194 :005 > HighVoltage::PagesController
 => HighVoltage::PagesController 
1.9.3p194 :006 > HighVoltage::PageFinder
NameError: uninitialized constant HighVoltage::PageFinder
    from (irb):6
    from /home/frozenmouse/.rvm/gems/ruby-1.9.3-p194@<my-project>/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
    from /home/frozenmouse/.rvm/gems/ruby-1.9.3-p194@<my-project>/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
    from /home/frozenmouse/.rvm/gems/ruby-1.9.3-p194@<my-project>/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

It seems that PageFinder was not getting reloaded.

Using autoload in module HighVoltage works for me, and the require directive in pages_controller.rb is no longer needed. But I have no idea how to write test for this...


Just verified it. This is a problem with the master branch now. We will make the change soon.


+1 Just ran into this problem...

@harlow harlow was assigned

@frozenmouse thanks for working with us on this. Historically we've shy'd away from autoload could we require high_voltage/page_finder explicitly?

require 'high_voltage/version'
require 'high_voltage/page_finder'

module HighVoltage

Let me know if that works for you. If you could update the PR I'll get it merged into master ASAP.


@harlow Can you explain why you don't like autoload? Just wondering...


Code-loading, including autoload, is not guaranteed to be thread-safe so far as I am aware.


Seems to be the case. Thanks for the explanation!


Added the require to lib/high_voltage.rb, has been added to master:

@harlow harlow closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  app/controllers/high_voltage/pages_controller.rb
@@ -1,5 +1,3 @@
-require 'high_voltage/page_finder'
class HighVoltage::PagesController < ApplicationController
layout { |_| HighVoltage.layout }
2  lib/high_voltage.rb
@@ -15,4 +15,6 @@ def self.setup
require 'high_voltage/engine' if defined?(Rails)
+ autoload :PageFinder, 'high_voltage/page_finder'
Something went wrong with that request. Please try again.