Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Deleting Todo Lists

Ralph Johnson
Ralph Johnson
10,408 Points

What about the confirm dialog?

I don't understand why the test Jason wrote actually works in the video. When you click Destroy in "real life," it triggers a confirm dialog box--you have to click "OK" or "cancel." That's not included in the code from the video.

My test (copied verbatim from the video and proofread several times) doesn't work, either. The test fails.

But I don't understand how it would work at all, given the confirm dialog.

1 Answer

Milo Winningham
seal-mask
.a{fill-rule:evenodd;}techdegree
Milo Winningham
Web Development Techdegree Student 3,317 Points

The code for the confirm dialog is generated as part of the scaffold. In app/views/todo_lists/index.html.erb, you can see it as part of the Destroy link:

<td><%= link_to 'Destroy', todo_list, method: :delete, data: { confirm: 'Are you sure?' } %></td>

The data hash there causes Rails to output a data-confirm attribute on the link tag. Then, the default Rails/jQuery integration (the jquery_ujs included in your application.js file) looks for this data attribute and shows the confirmation dialog when the link is clicked.