Skip to content

Instantly share code, notes, and snippets.

@swanson
Last active April 28, 2020 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save swanson/fa22e417b805f8da9a20d3ea70391f4f to your computer and use it in GitHub Desktop.
Save swanson/fa22e417b805f8da9a20d3ea70391f4f to your computer and use it in GitHub Desktop.
:plain
var existingModal = document.querySelector("[data-controller='modal']");
if (existingModal) {
document.body.removeChild(existingModal);
}
document.body.insertAdjacentHTML("beforeend", "#{j render partial: template.to_s}");
class CommercialPayersController < ApplicationController
def edit
render :as_modal, locals: { template: "form" }
end
def update
if @payer.update(payer_params)
redirect_to @payer, notice: "Successfully updated Commercial Payer"
else
render :as_modal, locals: { template: "form" }
end
end
end
// note you could move the "modal" markup to shared template if you want
.modal(data-controller="modal")
.modal-content.w-600
= form_with model: @payer do |f|
%h2.font-light.text-3xl.text-grey-700.mb-8
Edit Payer
.input-group
= f.label :name, "Payer Name"
= f.text_field :name, placeholder: "Enter a name..."
.input-group
= f.label :description
= f.text_field :description, placeholder: "Enter a short description..."
.text-right
.btn-secondary.mr-4(data-action="click->modal#close")
Cancel
= f.submit "Save", class: "btn"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment