試圖摧毀一個「貢獻」一個用戶的投票時,我收到以下錯誤:沒有路由匹配{:動作=>「消滅」
No route matches {:action=>"destroy", :controller=>"contribution_votes",
:id=>#<ContributionVote contribution_id: 8245, user_id: 40>}
但不知道爲什麼。這裏是按鈕發送請求
<%= button_to "undo voteup!",
contribution.contribution_votes.find_by_user_id(current_user),
:method => :delete, :class => 'contribution_vote undo' %>
這裏是在控制器中的「毀滅」行動:
def destroy
@vote = current_user.contribution_votes.find(params[:id])
@vote.destroy
@contribution = Contribution.find_by_id(@vote.contribution_id)
@contribution_decrement = @contribution.decrement(:votes)
if @vote.destroy and @contribution_decrement.save
respond_to do |format|
format.html {redirect_to :back}
format.js
end
else
redirect_to :back
end
end
(這裏有些冗餘,我知道,但它是在以填寫稍後的日期)
而這裏的設置在routes.rb
resources :contribution_votes, :only => [:create, :destroy]
任何人都可以幫忙嗎?我懷疑答案是顯而易見的,但我無法在任何地方找到它。順便說一句
<%= button_to "undo voteup!",
contribution_votes_path(current_user.id),
:method => :delete, :class => 'contribution_vote undo' %>
..::
你能告訴我們該按鈕生成的HTML嗎? – Nerian 2011-06-14 16:09:01
@John - 我對rails非常陌生,所以不知道如何去補救(我也不知道爲什麼我使用的是嵌套資源,但會查找它)。有什麼方法可以明確設置控制器嗎?爲什麼它不會尋找正確的控制器?謝謝你的幫助。 – jonic 2011-06-14 16:47:59
您在更改路由後是否重新啓動了服務器? – Arsen7 2011-06-14 19:31:23