데이터베이스의 특성에 대해 true/false를 토글하는 링크가 있습니다. 두 개의 서로 다른 속성에 대해이 두 가지 버전의 링크가 있습니다. 하나는 작동하고 다른 하나는 작동하지 않습니다. 특정 ID를 강제로 작동시킬 때를 제외하고는 정상적으로 작동합니다. 작업 링크의Ruby Rails : 컨트롤러가 ID를 제대로 전달하지 못합니까?
보기 :
<h1><%= link_to "Toggle True", toggle_completed_true_task_path(@task), :remote => true %></h1>
<h1><%= link_to "Toggle False", toggle_completed_false_task_path(@task), :remote => true %></h1>
작업 컨트롤러의 전망 :
respond_to :html, :js
def toggle_completed_true
@task = Task.find(params[:id])
@task.update_attributes(:completed => true)
end
respond_to :html, :js
def toggle_completed_false
@task = Task.find(params[:id])
@task.update_attributes(:completed => false)
end
실패 링크보기 :
<h1><%= link_to "Toggle True", toggle_confirmed_true_task_path(@task), :remote => true %></h1>
<h1><%= link_to "Toggle False", toggle_confirmed_false_task_path(@task), :remote => true %></h1>
실패 컨트롤러의 전망 :
respond_to :html, :js
def toggle_confirmed_true
@task = Task.find(params[:id])
@task.update_attributes(:confirmed => true)
end
respond_to :html, :js
def toggle_confirmed_false
@task = Task.find(params[:id])
@task.update_attributes(:confirmed => false)
end
저는 몇 시간 동안이 작업을 해왔고 저의 삶 때문에 왜 실패해야하는지, 다른 작업을해야하는지 알 수 없습니다.
이<h1><%= link_to "Toggle True", toggle_confirmed_true_task_path(12), :remote => true %></h1>
내가 변수 패스 얻을 특정 오류는 다음과 같습니다 : 참고이 모두 같은 페이지와 내가 지금처럼 특정 ID에 전달하면 작동이 작동하지 않습니다 하나에 표시 "경로가 일치하지 않습니다 {: action =>"toggle_confirmed_true ", : controller =>"tasks ", : id => nil"
어떤 통찰력이라도 대단히 감사합니다.
routes.rb 파일에 추가하는 것을 잊지 않았습니까? – MrDanA
내 대답이 네이선을 도왔나요? – MrYoshiji