如何解决没有路线匹配{:action =>“ destroy”
| 尝试破坏用户对“贡献”的投票时出现以下错误: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的任何地方都找不到。
解决方法
将您的代码更改为(我认为这会有所帮助):
<%= button_to \"undo voteup!\",contribution_votes_path(current_user.id),:method => :delete,:class => \'contribution_vote undo\' %>
..顺便说一句:在控制台中键入“ 5”,并确认您使用正确的路由路径(我可能会误解)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。