Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10520 (closed defect: fixed)

Opened 7 months ago

Last modified 3 months ago

[PATCH] Dependency bug in rails 2.0.1

Reported by: akaspick Assigned to: lifofifo
Priority: high Milestone: 2.x
Component: Railties Version: edge
Severity: major Keywords: bug dependency
Cc:

Description

A dependency error occurs in rails 2.0.1 using to_prepare in the environment.rb file.

Steps to recreate the error:

1) create a test app...

rails test_app

2) edit config/environment.rb and add...

config.to_prepare do end

3) run script/server <- no errors

4) run script/console <- dependency error

Can a core member submit a fix for this?

Attachments

to_prepare.patch (0.5 kB) - added by lifofifo on 12/16/07 23:39:04.
to_prepare.diff (0.6 kB) - added by akaspick on 12/29/07 22:41:58.
same fix as previous patch, but diff made from rails root (if that helps)

Change History

12/16/07 23:39:04 changed by lifofifo

  • attachment to_prepare.patch added.

12/16/07 23:45:16 changed by david

  • summary changed from Dependency bug in rails 2.0.1 to [PATCH] Dependency bug in rails 2.0.1.

12/29/07 22:41:58 changed by akaspick

  • attachment to_prepare.diff added.

same fix as previous patch, but diff made from rails root (if that helps)

01/01/08 13:46:03 changed by remvee

  • component changed from ActiveRecord to Railties.

+1 (Verified using Rails-2.0.2)

01/18/08 04:29:39 changed by Radar

+1 Also verified using Rails 2.0.2

01/18/08 13:34:40 changed by lifofifo

I guess we'll need to investigating a little more into the fix I suggested. I'm still not very clear/satisfied about appropriate use cases of to_prepare callbacks. What is it that you do in to_prepare callbacks that you cannot do witj after_initialize callbacks ?

Thanks.

01/18/08 19:49:53 changed by akaspick

  • version changed from 2.0.1 to edge.

My usage of to_prepare dynamically generates some ActiveRecord classes and various associations with existing classes.

Regardless of my usage, the error still occurs with no code in the to_prepare block as outlined in my example.

02/07/08 10:42:39 changed by svenfuchs

lifofifo, we're still using config.to_prepare to patch application classes from plugins. It's most probably not what this hook initially has been meant for. But it's a place where you can hook in stuff that needs to be re-run when app classes have been unloaded.

02/29/08 13:58:02 changed by agile

+1

03/22/08 22:30:02 changed by olek

+1

patch verified to work on rails 2.0.2

For those that need fix NOW (who does not?) and do not want to keep vendor/rails, here is quick monkey patch, paste in environments.rb just before first call to config.prepare_to:

#fixes rails bug described here: http://dev.rubyonrails.org/ticket/10520
#this monkey patch should be removed when problem is fixed in rails
  module Rails
    class Configuration
      def to_prepare(&callback)
        after_initialize do 
          require 'dispatcher' unless defined?(::Dispatcher) 
          Dispatcher.to_prepare(&callback) 
        end 
      end
    end
  end

03/24/08 21:47:34 changed by david

  • owner changed from core to michael@koziarski.com.

04/01/08 15:46:42 changed by nzkoz

  • owner changed from michael@koziarski.com to lifofifo.

04/02/08 12:48:13 changed by pratik

  • status changed from new to closed.
  • resolution set to fixed.

(In [9211]) Fix that config.to_prepare dependency error. Closes #10520 [akaspick, Pratik]