Reputation: 296
in my application.html, i have this inside:
...
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
...
in my _post.html, i have the follow block to allow users to delete posts:
<% if current_user == post.user or can? :manage, :all %>
<span class ="plaintext"> [<%= link_to_if(can?(:delete, post), 'Delete', post_path(post), :class=>'delbuttons', :id=>'delete', :confirm => "Are you sure?", :method => :delete) {} %>]
</span>
<% end %>
for some reason, though, having the line prevents my posts from being deleted! it's very weird. how do i enable deletion again? i'm on Rails 3.
Upvotes: 0
Views: 75
Reputation: 2663
As most browsers don't natively support the delete HTTP verb, rails uses javascript to be able to perform a delete action. To have this working with jquery you'll need to include a version of rails.js that works with jQuery (and the version of jQuery you are using).
You can get the latest copy of jQuery here: http://code.jquery.com/jquery-1.7.1.min.js And grab the latest rails.js here: https://raw.github.com/rails/jquery-ujs/master/src/rails.js
Update your application layout to include both like so:
<%= javascript_include_tag 'jquery-1.7.1.min.js' %>
<%= javascript_include_tag 'rails.js' %>
Upvotes: 1