Project

glow

0.01
No commit activity in last 3 years
No release in over 3 years
Handles Flash messages in Javascript for Rails xhr-responses. Fires a dom event when flash messages are present.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 4.0.0
>= 4.0.0
 Project Readme

Glow

Glowing flashes! Okay... not really. This simply adds handling of the Flash Hash in Javascript. Depends on jQuery.

CI

The CI travis.com is disabled because of our migration to Github Actions. If the project is reactivated or the code needs to be changed you should migrate the CI-steps to Github Actions.

Usage

Any flash messages set in ajax responses fire a glow:flash event on document.

flash[:notice] = 'Ajax man!'
respond_to do |format|
  format.js { head :ok }
end

Handle it any way you want:

$(document).bind('glow:flash', function(evt, flash) {
  alert(flash.type);
  alert(flash.message);
});

Also adds a Flash object that enables you to fire glow:flash.

Flash.success('Yeah this worked!');
Flash.error('Something went wrong!');
Flash.notice('This is a flash message');

Flash.fire('type', 'message');

This can be used to unify your Flash message handling (also in non-xhr responses).

<% flash.each do |type, message| %>
  <%= javascript_tag "Flash.fire('#{type}', '#{message}')" %>
<% end %>

If you want to skip the glow after_action just set flash[:skip_glow].

You can also use glow with APIs by using headerize_flash_for and passing in the request formats you want the flash messages passed back.

class API::Base < ActionController::Base
  headerize_flash_for :json
end

Controllers inheriting from a controller using headerize_format_for will inherit the capability or it can be overridden.

class API::JSON < API::Base
  # will headerize flash for JSON requests
end

class API::XML < API::Base
  headerize_flash_for :xml
  # will NOT headerize flash for JSON requests
  # but will headerize flash for XML requests
end

Installation

In your gemfile add

gem "glow"

.

Rails >= 4

Add

//=require glow

to your manifest.

License

See MIT-LICENSE.