Created
February 21, 2013 08:21
-
-
Save joeljackson/5003155 to your computer and use it in GitHub Desktop.
And after some simple refactoring
This file contains hidden or 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
module Notifiable | |
def self.included(klass) | |
klass.has_many :notifications | |
end | |
def notified_users | |
User.where("id in (?)", self.notifications.map(&:user_id) | |
end | |
end | |
class Post < ActiveRecord::Base | |
include Notifiable | |
belongs_to :user | |
end | |
class Photo < Post | |
has_attached :picture | |
end | |
class NotifiableCreator | |
def initialize(notifiable) | |
@notifiable = notifiable | |
end | |
def create | |
result = @notifiable.create | |
if result | |
UserNotifier.new(self).notify | |
end | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment