var modalSelector = "#<%= dom_id @tag, dom_id(@releasable) %>"
var modal = "<%= j render("new_tag_modal", releasable: @releasable, tag: @tag) %>"

// If the modal already exists, replace it. Otherwise, create it
if ($(modalSelector).length > 0) {
  $(modalSelector).replaceWith(modal)
} else {
  $('body').append(modal)
}

$(modalSelector).modal("toggle")