Skip to content

Instantly share code, notes, and snippets.

@neerajsingh0101
Created April 22, 2011 04:59
Show Gist options
  • Save neerajsingh0101/936051 to your computer and use it in GitHub Desktop.
Save neerajsingh0101/936051 to your computer and use it in GitHub Desktop.
module SpreeSite
class Engine < Rails::Engine
def self.activate
Order.class_eval do
def artworks; true; end
end
end
config.to_prepare &method(:activate).to_proc
ActionDispatch::Callbacks.after { SpreeSite::Engine.activate } #<<<<- I added this line
end
end
=begin
reload! reloads all the engines, calls to_prepare and then removes
constants ( in that order). Note that when you call console! then the
constants are dropped at the very end. So after console! when you do
> Order.first
then vm does not find Order already loaded since it was removed at the
end of console!. Now because of autoloading Order is loaded from app/models
but this Order does not have the artworks method.
Solution:
ActionDispatch::Callbacks provide an "after" hook. I used it to reload
Order class after Order class was removed. And this Order class is
properly decorated with artworks method.
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment