Skip to content

Instantly share code, notes, and snippets.

@marcioj
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save marcioj/ff722a3e0e7169a9597c to your computer and use it in GitHub Desktop.

Select an option

Save marcioj/ff722a3e0e7169a9597c to your computer and use it in GitHub Desktop.
Rerenders the result of an ajax request into the fancybox modal. Good for form redisplays
= simple_form_for([@topic], remote: true, data: { "rerender-inside-modal" => true }) do |f|
= f.input :name
= f.input :content
= f.submit
$(document).on("ajax:complete", "form[data-rerender-inside-modal]", function(evt,xhr) {
// make sure that server responded with a html content, otherwise ignore it
if (xhr.getResponseHeader("Content-Type").indexOf("text/html") !== -1) {
$.fancybox({ content: xhr.responseText });
} else {
$.fancybox.close();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment