shuffling the application load order around

I want to shuffle things around so that routes and observers are
loaded last, after plugins, the after_initialize callbacks, and the
application initializers. Here's the problem:

1) I add a gem (has_finder) to a file in config/initializers
2) It is used in my User model
3) AR initializes my UserObserver model, which loads User, before the
config/initializers run
4) BOOM, undefined method #has_finder

This issue is easily worked around, but this small change in the load
order makes sense to me.

http://dev.rubyonrails.org/attachment/ticket/10980/load_order.diff

Can anyone think of any issues?

I think this would also fix this issue:

http://robsanheim.com/2008/01/08/rails-observers-make-rake-dbmigrate-crash-from-version-0/

- Rob

Well, let me know... that would be a plus.

+1.

Even if there are issues, it's still the right thing to do.
"Initialization" should happen first.

-- Chad

+1

Instantiating an observer triggers loading its observed model class to register it, and I think the model class should be allowed to expect full initialization. Particularly we are concerned here with extensions to Active Record by plugins or initializers.

If you happen to be creating observed models in config/initializers you can still manually instantiate the singleton. So there's some price here, but you still have a simple solution, and I believe the use cases above are far more important.

I've added a documentation patch:

    http://dev.rubyonrails.org/attachment/ticket/10980/document_observers_loading.diff

-- fxn

Thanks for the input, everyone. I just committed it.

I also got another suggestion from Sven that the after_initialize hook
should run *after* the config initializers. That makes sense to me,
personally. So, please let me know if either of my changes breaks
something.