Skip to content

Instantly share code, notes, and snippets.

@dfreerksen
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfreerksen/dd8c7235f0dd431c0c59 to your computer and use it in GitHub Desktop.
Save dfreerksen/dd8c7235f0dd431c0c59 to your computer and use it in GitHub Desktop.
# app/controllers/spree/checkout_controller_decorator.rb
Spree::CheckoutController.class_eval do
after_action :after_order_processing
def after_order_processing
# This doesn't seem to be called either. Also I would have to check the
# current state each time this ran for the 'complete' state
binding.pry
end
end
# app/models/spree/order_decorator.rb
Spree::Order.class_eval do
# Adding after_transition to state doesn't work
state_machine.after_transition to: :complete,
do: :after_order_processing
def after_order_processing
binding.pry
end
# Aliasing method doesn't work
def finalize_with_notify_service!
finalize_without_notify_service!
binding.pry
end
alias_method_chain :finalize!, :notify_service!
end
@dfreerksen
Copy link
Author

Turns out I was missing something in engine.rb to load in files with the _decorator.rb suffix. Once I added it, things started working.

module SpreeEngineName
  class Engine < ::Rails::Engine
    ...

    def self.activate
      Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator.rb")) do |c|
        Rails.configuration.cache_classes ? require(c) : load(c)
      end
    end

   config.to_prepare &method(:activate).to_proc

   ...
  end
end

@adriano-tirloni
Copy link

Nice!

@braidn
Copy link

braidn commented May 8, 2015

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment