README.md in glow-0.0.12 vs README.md in glow-0.0.13
- old
+ new
@@ -6,21 +6,25 @@
## 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
+```ruby
+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);
- });
+```javascript
+$(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!');
@@ -34,9 +38,36 @@
<% flash.each |type, message| %>
<%= javascript_tag "Flash.fire('#{type}', '#{message}')" %>
<% end %>
If you want to skip the glow after_filter 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.
+
+``` ruby
+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.
+
+``` ruby
+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