Skip to content

Instantly share code, notes, and snippets.

@gosuri
Created January 10, 2012 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gosuri/1591273 to your computer and use it in GitHub Desktop.
Save gosuri/1591273 to your computer and use it in GitHub Desktop.
# 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
end
flash.discard # don't want the flash to appear when you reload page
end
=begin
# js
$(document).ajaxError(function(event, request) {
var flash = request.getResponseHeader('X-Flash');
// Do something
});
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment