Last active
August 29, 2015 13:58
-
-
Save scaint/9995582 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product < ActiveRecord::Base | |
attr_accessor :publisher | |
# ... | |
before_save { publisher.try(:broadcast, :before_save self) } | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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