尝试破坏用户对“贡献”的投票时出现以下错误:
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]
任何人都可以帮忙吗?我怀疑答案很明显,但我在 SO 上的任何地方都找不到。