public
Created

  • Download Gist
flash.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.