This project is archived and is in readonly mode.

#443 ✓invalid
Daniel Lockhart

Constants no longer available at load in 2.1.0

Reported by Daniel Lockhart | June 18th, 2008 @ 01:03 AM

I have a constant PLATFORM_INTERFACE assigned in my environment.rb. This constant references a module that is included in many other models throughout my app. (It is a constant as the module varies depending on the platform the app is running on)

For example, my application controller has the line:

include PLATFORM_INTERFACE

Prior to 2.1, this worked fine. However, as of 2.1 it throws an uninitialized constant error whenever it is included in a class: for example

'uninitialized constant ApplicationController::PLATFORM_INTERFACE'

So it appears that constant that is assigned in environment.rb is not available when the application controller (as well as all other controllers and models) are loaded. There was no mention of a change in the load order for 2.1, so I am going to assume it is a bug.

Comments and changes to this ticket

  • Daniel Lockhart

    Daniel Lockhart June 18th, 2008 @ 06:20 PM

    So after more investigation, it turns out the problem only occurs in plugins as long as you preface the constant with :: (The :: was not necessary pre-2.1.0) The error still occurs when a plugin tries to reference the constant, whether prefixed with :: or not.

    A workaround is to use .send :include in the environment.rb.

  • josh

    josh June 18th, 2008 @ 06:24 PM

    • State changed from “new” to “invalid”
    • Milestone cleared.

    Avoid initializing stuff in environment.rb. Use the initializers folder.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Tags

Pages