I'm trying to send a notification to a user with Mailboxer, and I need to pass an object along which will affect how the notification is displayed in my navbar's notification dropdown.
@recipient.notify("#{current_user.name} needs you to review his help with: #{@offer.title}", "#{@message}", @offer)
The last argument is where I'm trying to pass the object, @offer
.
This is the Mailboxer method which I'm trying to use:
def notify(subject,body,obj = nil,sanitize_text=true,notification_code=nil,send_mail=true)
Mailboxer::Notification.notify_all([self],subject,body,obj,sanitize_text,notification_code,send_mail)
end
It calls this notify_all
method:
def notify_all(recipients, subject, body, obj = nil, sanitize_text = true, notification_code=nil, send_mail=true)
notification = Mailboxer::NotificationBuilder.new({
:recipients => recipients,
:subject => subject,
:body => body,
:notified_object => obj,
:notification_code => notification_code
}).build
notification.deliver sanitize_text, send_mail
end
When I try to access object with this: <%= notification.object_id %>
, I get a long number like 205981093
. And I get an error if I try to access one of the offer
object's fields with this: <%= notification.object_id.title %>
`undefined method `title' for 2166878920:Fixnum`
I'm not even sure if this is the way Mailboxer Notifications are used. I've had a very difficult time finding info on them. Any help is greatly appreciated.
Try the following to get your unread notifications
current_user.mailbox.notifications(:read => false)