2

「投稿」に対するユーザーの投票を破棄しようとすると、次のエラーが発生します。

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のどこにも見つかりません。

4

1 に答える 1