Are there any good tutorials or gems that handle Rails Flash messages via Ajax?
In my .js.erb files, I've used something like the following:
<% if @event.errors.any? %>
<% @event.errors.keys.each do |key| %>
$( "#event_<%= j key.to_s %>" ).addClass("errorField");
<% end %>
$("#flashMSG").css("display", "block");
if(!$(".flashError").length){
$("<div class='flashError'>").html("Sorry, please fill in required fields.").appendTo(".noticeContainer");
}
<% else %>
$(document).bind("ajax:success", function(e, data, status, xhr) {
$("#flashMSG").slideUp(400).delay(400).slideDown();
if(!$(".flashSuccess").length){
$("<div class='flashSuccess'>").html("Event Updated.").appendTo(".noticeContainer");
}
});
<% end %>
Just wondering if there's a better way to do this or automate it similar to how Rails just handles it with a standard form submission.