Skip to content
Sean C Davis edited this page Sep 5, 2016 · 2 revisions

Note: It's important you understand how to use notify_on within a model and understand how its options work before configuring your app's notifications using bulk configuration.

NotifyOn was built for direct injection into the model for the object triggering a notification. But, given all the potential options for any given notification, our models quickly became girthy—littered with notification settings.

We create the bulk configuration to help you keep your models skinny and to be able to see your app's notification settings at a glance.

When you run the installer (bundle exec rails g notify_on:install) you are given a bulk configuration file: config/notifications.yml. This is where you bulk config goes.

In general, each notification will be look very much like it would were you to use notify_on within a model, only we're using YAML instead of Ruby.

The syntax looks like this:

underscored_model_name:
  notification_01_name:
    when: :action
    link: trigger_path(:self)
    message: '{name} did something crazy!'
    # additional notification 01 options ...
  notification_02_name:
    # notification 02 options ...

another_model:
  # notifications for AnotherModel ...

Notice:

  • Each notification is placed underneath its underscored model name. e.g. Message would be written as message:, or SuperUser would be written as super_user:.
  • The notification name, while arbitrary, must be unique. YAML will overwrite identical keys.
  • The action parameter (when using notify_on in a model) must be stated as when:.
  • YAML values are strings by default, so something like trigger_path(:self) does not have to be wrapped in quotes.
  • But YAML also tries to interpolate curly braces, so anything using NotifyOn's string interpolation must be wrapped in quotes.

Last, all the bulk configuration really does is convert this YAML file into individual notify_on calls (it's a glorified alias for notify_on). And it only does this when the server is initialized. Therefore, you must restart your server when making changes to your bulk configuration.