As others have stated, access to the controller from an observer somewhat violates the MVC principle. Also, these answers correspond to your specific use case.
But , if you need a more general solution, you can try to customize the way the Rails Blenders are .
Sweepers are ordinary observers, but they provide access to the controller if the observer is called from the controller.
- , , , (.. Singleton)
, :
- , .
singleton around_filter :
class ApplicationController < ActionController::Base
around_filter MyObserver.instance
end
:
attr_accessor :controller
def before(controller)
self.controller = controller
true
end
def after(controller)
self.controller = nil
end
. controller nil, .