Create a gist now

Instantly share code, notes, and snippets.

# May not be the best approach
# Issues with Proxies limititing headers
# Headers could be cached
# Not sure of having JSON
class ApplicationController < ActionController::Base
after_filter :flash_to_headers
def flash_to_headers
return unless request.xhr?
unless flash.empty?
response.headers['X-Flash'] = flash.to_json
flash.discard # don't want the flash to appear when you reload page
# js
$(document).ajaxError(function(event, request) {
var flash = request.getResponseHeader('X-Flash');
// Do something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment