2

I am currently deleting a record using the following:

<%= link_to "Delete", user_path(user), data: { confirm: "Are you sure?"}, method: :delete %>

I was wondering how would I go about using a modal to confirm the deletion?

I want to display a modal (bootstrap), and then have an input box that forces the user to type in the word 'DELETE'. After hitting submit, it then actually deletes the record.

How would I do that?

Blankman
  • 259,732
  • 324
  • 769
  • 1,199

1 Answers1

2

Instead of using the confirm attribute to pop up a browser alert window (the default behavior), you could. . .

Write a javascript action that will open a modal (many examples of this online, like this one written in coffeescript) with both a text field and a disabled delete link.

Using javascript, check for changes in the text field using, when the text in the text field reads: 'DELETE', use javascript to enable the delete link.


Note that this solution will not work if a user is browsing your site with javascript disabled, but neither would many other browser-side confirmation type things.

Community
  • 1
  • 1
Ecnalyr
  • 5,792
  • 5
  • 43
  • 89