2011-06-14 4 views
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] 

아무도 도와 줄 수 있습니까? 나는 그 대답이 분명한 것 같지만 아무데도 그것을 찾을 수 없다. 그런데

<%= button_to "undo voteup!", 
    contribution_votes_path(current_user.id), 
    :method => :delete, :class => 'contribution_vote undo' %> 

...을 :

+0

버튼의 생성 된 html을 표시 할 수 있습니까? – Nerian

+0

@ 존 - 저는 레일에 새로 온 사람입니다. 그래서 그것을 교정하는 법을 알지는 못합니다. (왜 내가 사용하고있는 것이 중첩 된 자원인지는 모르지만 그것을 살펴볼 것입니다). 컨트롤러를 명시 적으로 설정할 수있는 방법이 있습니까? 왜 올바른 컨트롤러를 찾지 않을까요? 당신의 도움을 주셔서 감사합니다. – jonic

+0

경로를 변경 한 후 서버를 다시 시작 했습니까? – Arsen7

답변

1
(나는 그것이 도움이 될 것입니다 생각)에보기에서 코드를 변경

콘솔에 입력 rake routes을하고 바로 라우팅 경로를 사용하는지 확인 (내가 실수를 할 수 있습니다) .

+0

컨트롤러가 id = user.id 인 contrib_vote를 찾으려고 시도 했으므로 아마 작동하지 않는 것 같습니다. 이 양식은 current_user.id와 contribution.id를 모두 통과해야 삭제할 오른쪽 contrib_vote를 식별 할 수 있습니다 ... – jonic

+0

경로도 괜찮아 보입니다 :'contrib_vote DELETE /contribution_votes(.:format) {: controller => "contribution_votes" , : action => "destroy"} ' – jonic

+0

하지만 어쨌든 bor1s 감사합니다! – jonic

관련 문제