-
Notifications
You must be signed in to change notification settings - Fork 1
String Interpolation
NotifyOn comes with a custom string interpolator for injecting an object's attributes into notify_on
options. We can't use Ruby's built-in interpolatation because we don't have an instance at the time we define notify_on
in our model.
NotifyOn's string interpolation syntax is similar to Ruby's. It simply omits the leading #
character. Here's an example:
:message => '{author.email} sent you a message.'
Notice that you also have the option to daisy-chain methods together.
IMPORTANT: The code that is interpolated is executed within an instance of the object that triggered the notification. Therefore, the code within the curly braces must be able to be executed on an instance of the model where it is defined.
Also take note that you don't use symbols to represent objects here, like you would in other notify_on
settings. However, there are some built-in methods that you may use:
-
:env
resolves toRails.env.to_s
. -
:recipient_id
resolves to the id of the object receiving the notification.