当我试图破坏用户对“贡献”的投票时,我得到了以下错误:
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]有人能帮上忙吗?我怀疑答案是显而易见的,但我在任何地方都找不到。
发布于 2011-06-15 00:09:48
将视图中的代码更改为(我认为这会有所帮助):
<%= button_to "undo voteup!",
contribution_votes_path(current_user.id),
:method => :delete, :class => 'contribution_vote undo' %>。。顺便说一句:在控制台中键入rake routes,并验证您使用的路由路径是否正确(我可能会弄错)。
https://stackoverflow.com/questions/6346539
复制相似问题