Created
September 28, 2011 22:43
-
-
Save jsmestad/1249457 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ajaxComplete(function(event, request) { | |
| var flash = $.parseJSON(request.getResponseHeader('X-Flash-Messages')); | |
| if (!flash) return; | |
| if (flash.notice) $('.notice').html(flash.notice); | |
| if (flash.error) alert(flash.error); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ApplicationController < ActionController::Base | |
| protect_from_forgery | |
| after_filter :flash_to_headers | |
| private | |
| def flash_to_headers | |
| return unless request.xhr? | |
| flash_json = Hash[flash.collect do |type, messages| | |
| [k, messages.is_a?(Array) ? messages.collect {|i| ERB::Util.h(i)} : ERB::Util.h(messages)] | |
| end].to_json | |
| response.headers['X-Flash-Messages'] = flash_json | |
| flash.discard | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment