Friday, October 12, 2012

Avoiding "warning: already initialized constant" in Rails startup

To avoid "warning: already initialized constant" in Rails, assume that you have a require somewhere that is reloading an autoloaded module.

For example:

in app/controllers/something.rb:

module Something
  OPTIONS = [:test]
  # ...
end

in app/controllers/something/another_module.rb:

# require 'something' # if this is uncommented, it will try to load the module twice on startup

module Something
  module AnotherModule
    extend ActiveSupport::Concern
    # ...
  end
end

No comments: