Skip to content

Instantly share code, notes, and snippets.

@scaint
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scaint/9995582 to your computer and use it in GitHub Desktop.
Save scaint/9995582 to your computer and use it in GitHub Desktop.
class Product < ActiveRecord::Base
attr_accessor :publisher
# ...
before_save { publisher.try(:broadcast, :before_save self) }
end
class ProductController < ApplicationController
# ...
def create
product = Product.new(product_params)
my_publisher = Publisher.new
my_publisher.on(:before_save, EventListener.new)
product.publisher = my_publisher
# ...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment