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.

Can anyone think of any issues?

I think this would also fix this issue:

- Rob

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


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

-- Chad


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:

-- 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