开发者

Rails - Creating a Delete Link

开发者 https://www.devze.com 2023-01-23 04:41 出处:网络
I\'m using the following for a delete link: <%= link开发者_如何学编程_to \"Delete\", photo_path(@photo.id), :confirm => \"Are you sure?\", :method=>:delete %>

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消