Skip to content

Instantly share code, notes, and snippets.

@joeljackson
Created February 21, 2013 08:21
Show Gist options
  • Save joeljackson/5003155 to your computer and use it in GitHub Desktop.
Save joeljackson/5003155 to your computer and use it in GitHub Desktop.
And after some simple refactoring
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