I have setup Public Activity to show notifications. Notifications are created with right recipient.
Now I want to send out email to notification recipient.
Normally I'd call the mailer on controller create. But on notifications controller I got only index with:
def index
@activities = PublicActivity::Activity.where(recipient_id: current_user.id).includes(:owner).includes(:trackable).all.reverse
end
And for instance on comment.rb I have:
include PublicActivity::Model
tracked
tracked owner: Proc.new{ |controller, model| controller.current_user }
tracked recipient: ->(controller, model) { model && model.commentable.user }
And on view comment_create
<li class="list-group-item">
<span class="glyphicon glyphicon-plus"></span>
<small class="text-muted"><%= a.created_at.strftime('%H:%M:%S %-d %B %Y') %></small><br/>
<strong><%= activity.owner ? activity.owner.name : current_user.name %></strong> commented
- <%= a.trackable.body %> - to
<%= link_to 'this item you posted.', poll_path(a.trackable.commentable_id) %>
</li>
I guess the creation of the notification is done internally by the gem.
Where should I call the mailer then?
You can put the mailer in a background job and then call that in the controller index.