AnApprentice
AnApprentice

Reputation: 111070

Rails - Creating a Delete Link

I'm using the following for a delete link:

<%= link_to "Delete", photo_path(@photo.id), :confirm => "Are you sure?", :method=>:delete %>

Problem is, if I click CANCEL - it still deletes!!! wooops... Why is that?

Upvotes: 1

Views: 748

Answers (1)

Nicolas Blanco
Nicolas Blanco

Reputation: 11299

First, you don't have to write photo_path(@photo.id), just pass @photo, that's enough.

<%= link_to "Delete", @photo, :confirm => "Are you sure?", :method => :delete %>

If the link doesn't work, that means that your page doesn't correctly load the JavaScript adaptator for your JavaScript framework. For example, if you use use jQuery, check this :

http://github.com/rails/jquery-ujs

Upvotes: 2

Related Questions