Last active
August 29, 2015 14:00
-
-
Save madsheep/5350998caed83f69b33c to your computer and use it in GitHub Desktop.
less and less simple
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 Membership | |
belongs_to :user | |
belogns_to :group | |
after_save :send_notifications, if: ->(m) { m.accepted_changed? && m.accepted? } | |
def send_notifications | |
Resque.enqueue MembershipNotificationsWorker, self.id | |
end | |
end | |
class MembershipNotificationsWorker | |
def perform(membership_id, user_id) | |
membership = Membership.find(membership_id) | |
user = User.find(user_id) | |
NotificationMailer.accepted(membership, user).deliver! | |
PushNotifcations::NewMembership.new(membership, user).dispatch! | |
admins = membership.group.admins - user | |
admins.each do |admin| | |
NotificationMailer.accepted_admin(membership, admin).deliver! | |
PushNotifcations::NewMembershipForAdmin.new(membership, user).dispatch! | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment