Unobtrusive flash messages for Rails

October 10, 2013

I’d like to announce a gem that I wrote three years ago, then it got off my radar, albeit having some traction on RubyGems. I finally updated it to be compatible with recent technologies and also easier to use.

This gem is unobtrusive_flash, and it solves two common issues with flash messages in Rails (It has nothing to do with Adobe Flash. How do you unobtruse that, anyway?)

Firstly, it allows you to show Flash messages without having to render them inside your views. This allows views to be cached without worrying about stray flash messages cached within them.

Secondly, it lets you pass Flash messages along your AJAX responses, again, without affecting the response body. This allows you to add a bit of responsiveness to your AJAX calls without having to implement a custom notification system.

This is achieved with cookies, supported on any modern browser, and does not require more than 3 lines of configuration code. So it’s a great lightweight gem to add to your base application template. Now you don’t have to code anything to make flash messages appear!

The gem contains both a Bootstrap-based UI, and a generic barebones UI, but it can also be used with your custom UI, or a third-party plugin such as jGrowl.

The unobtrusive_flash page on Github has the instruction manual.

(looking for markup?)

  • **bold**
  • > quote

cancel