的問題是下面的Rails 3)刪除,Destory和路由
<%= button_to t('.delete'), @post, :method => :delete, :class => :destroy %>
我的職務模型的代碼有很多的關係依賴於刪除。但是,上面的代碼只會刪除帖子,使其關係保持不變。問題是方法delete和destroy在該方法中不同,delete不會實例化該對象。
所以我需要使用「銷燬」而不是「刪除」我的帖子。
<%= button_to t('.delete'), @post, :method => :destroy %>
給我路由錯誤。
沒有路由匹配[POST] 「/職位/ 2」
<%= button_to t('.delete'), @post, Post.destroy(@post) %>
刪除後沒有點擊的按鈕。
任何人都可以幫助我嗎?
UPDATE:
的application.js
//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require bootstrap-modal
//= require bootstrap-typeahead
//= require_tree .
耙路線
DELETE (/:locale)/posts/:id(.:format) posts#destroy
Post模型
has_many :tag_links, :dependent => :destroy
has_many :tags, :through => :tag_links
標籤模型
has_many :tag_links, :dependent => :destroy
has_many :posts, :through => :tag_links
問題: 當我刪除帖子,所有的tag_links被破壞,但標籤仍然存在。
你的路線文件是什麼樣的?你使用的是什麼JavaScript庫? – JPR
@JPR,檢查更新。路線文件只是使用我看到的腳手架POST路線(基本CRUD) –