The problem is the code below
<%= button_to t('.delete'), @post, :method => :delete, :class => :destroy %>
My Post model has many relations that are dependent on delete. However, the code above will only remove the post, leaving its relations intact. The problem is that methods delete and destroy are different in that method delete doesn't instantiate the object.
So I need to use "destroy" instead of "delete" my post.
<%= button_to t('.delete'), @post, :method => :destroy %> gives me routing error.
No route matches [POST] "/posts/2"
<%= button_to t('.delete'), @post, Post.destroy(@post) %> deletes the post without clicking the button.
Could anyone help me with this?
UPDATE:
application.js
//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require bootstrap-modal
//= require bootstrap-typeahead
//= require_tree .
rake routes
DELETE (/:locale)/posts/:id(.:format) posts#destroy
Post model
has_many :tag_links, :dependent => :destroy
has_many :tags, :through => :tag_links
Tag model
has_many :tag_links, :dependent => :destroy
has_many :posts, :through => :tag_links
Problem:
When I delete a post, all the tag_links are destroyed but tags still exist.