Last active
December 17, 2015 00:29
-
-
Save delba/5521784 to your computer and use it in GitHub Desktop.
Confirm delete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= 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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.getElementById('name').addEventListener 'input', -> | |
@form.commit.disabled = @value isnt @dataset.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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