Skip to content

Instantly share code, notes, and snippets.

@delba
Last active December 17, 2015 00:29
Show Gist options
  • Save delba/5521784 to your computer and use it in GitHub Desktop.
Save delba/5521784 to your computer and use it in GitHub Desktop.
Confirm delete
<%= form_tag @item, method: :delete do |f| %>
<%= label_tag :name, "Type the item's name to delete" %>
<%= text_field_tag :name, nil,
data: { name: @item.name }, autocomplete: 'off' %>
<%= submit_tag "Delete Item", disabled: true %>
<% end %>
document.getElementById('name').addEventListener 'input', ->
@form.commit.disabled = @value isnt @dataset.name
class ItemsController < ApplicationController
def destroy
@item = Item.find(params[:id])
@item.destroy if @item.name == params[:name]
redirect_to @item.destroyed? ? items_url : @item
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment