Recently in our platform we started using activity_notifications for in-platform notifications and email notifications. But we wanted to use our already styled template files.
If you are struggling with the same problem, then you have come to right place.
I am going to walk you through with basic setup of activity_notification emails and bootstrap_email and then using bootstrap_email styling for all activity_notifications.
1. Setting up ActivityNotification
To setup in-platform notification please follow gem's documentation
2. Setting up Email notification
To setup email notification please follow gem's documentation.
While following the documentation please make sure to include this
acts_as_target email: :email, email_allowed: :confirmed_at
in your target user model.
Once these two steps are ready you are good to go to start sending emails.
3. Setting up bootstrap email
To setup bootstrap for your emails, follow gem's documentation
Now, we have successfully enabled both the libraries in our platform. Now its the time to connect both of them.
4. Using custom mailer for activity_notification
While configuring activity_notification you must have created a config file for it, at
config/activity_notification.rb which defines all the settings of activity_notification.
Update this below line in
config/activity_notification.rb to use our custom mailer file.
config.mailer = "ActivityNotificationMailer"
And create a new file at
We are going to use this file to override one of the gem's function to use
bootstrap_email function instead of using
class ActivityNotificationMailer < ActivityNotification::Mailer layout 'whatever_layout_you_are_using_for_emails' def send_mail(headers, fallback = nil) begin make_bootstrap_mail headers rescue ActionView::MissingTemplate => e if fallback.present? make_bootstrap_mail headers.merge(template_name: fallback) else raise e end end end
Save this file and TADA you will be experiencing automated bootstrap styled emails getting sent from your platform.
Thank you for reading it out. Hope someone will find it helpful. And if you are that someone don’t forget to show us some love by giving some reactions and comments. :)
Posted on by:
Why is Rails ActiveRelation.update_all updating a different set of records?
Andy Zhao (he/him) -
Let's Build: With Ruby on Rails - A Blog with Comments
Andy Leverenz -
Crafting user notifications in Rails with Active Delivery
Vladimir Dementyev -
Building a Service-oriented Architecture with Rails and Kafka
Stella Cotton -