Skip to content

Instantly share code, notes, and snippets.

@julianrubisch
Created March 8, 2022 15:17
Show Gist options
  • Save julianrubisch/18ddd5a5c3205dc021ced283524b8cce to your computer and use it in GitHub Desktop.
Save julianrubisch/18ddd5a5c3205dc021ced283524b8cce to your computer and use it in GitHub Desktop.
class Event < ApplicationRecord
# Associations
belongs_to :owner, class_name: "User", optional: true
belongs_to :event_source, polymorphic: true
has_noticed_notifications
# ...
end
class EventNotification < ApplicationNotification
deliver_by :action_cable, format: :to_websocket, channel: "NotificationChannel"
deliver_by :email, mailer: "NotificationsMailer", method: :notify #, delay: 15.minutes, unless: :read?
param :event
def message
"#{event.event_source}: #{event.title}"
end
def url
target = [event.event_source.parent, event.event_source].compact
polymorphic_path(target.one? ? target.first : target)
end
def event
params[:event]
end
end
class NotificationsMailer < ApplicationMailer
def notify
@record = params[:record]
@recipient = params[:recipient]
# I'd like to get access to the Noticed::Base here
@message = @record.message
mail(
to: email_address_with_name(@recipient.email, @recipient.name),
from: Jumpstart.config.support_email,
subject: "Reactive Rails Reviews - Notification"
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment