aeolus-incubator / tim

Web application for managing virtual images to be deployed in the cloud
www.aeolusproject.org
MIT License
3 stars 6 forks source link

Get our ApplicationController to load. #46

Closed jguiditta closed 12 years ago

jguiditta commented 12 years ago

Previously, when mounting the engine in certain host apps (but strangely, not all), our ApplicationContoller was not getting initialized, which would cause strange issues when trying to call the tim api in those cases. We are supposed to get this for free, and it always works correctly in newly-generated rails 3.2.8 apps, but older apps that were upgraded seem to not behave correctly. This patch implements a simple initializer suggested on stackoverflow to make sure the class gets loaded.

http://stackoverflow.com/questions/11449464/rails-3-2-engine-weirdness-with-before-filter

It still seems to me none of this should be necessary, but I suspect it is some setting that older apps have, I just can't seem to find it. Open to other ideas, but this seems at least fairly well contained if we later find a way to ditch it

jprovaznik commented 12 years ago

Hi Jay, nice - thanks for this patch. For Conductor the problem is/was that Conductor's ApplicationController is always loaded before Tim's ApplicationController because Conductor references in config/initializers/warden.rb: config.failure_app = UserSessionsController which inherits from ApplicationController.

And if autoload is enabled in rails, then ruby won't load tim/application_controller (which defined Tim::ApplicationController class) because ruby already knows about global ::ApplicationController.

In other words this is not related to "newly-generated rails 3.2.8 apps" or some config option. This is loading issue which is not covered by current railsguides.

mtaylor commented 12 years ago

If this is the case, then wouldn't my original patch be the better solution.

It still allows rails to lazy load Tim::ApplicationController. The example from stackoverflow confirms what we expected in terms of how the classes are loaded/found when referenced within a module. Specifying the namespace inside the controllers will force Rails to load the correct ApplicationController class.

jguiditta commented 12 years ago

Closing this, Martyn has convinced me to go with his approach, which I will now push to master