2012-10-03 5 views
0

나는 다음과 같은 오류를 받고 있어요 일치하지 않습니다 :레일 3.2.1 라우팅 오류 없음 경로

attr_accessor :completed 
before_filter :find_list 

def create 
    @task = @list.tasks.new(params[:task]) 
    if @task.save 
    flash[:notice] = "Task created" 
redirect_to list_url(@list) 
    else 
flash[:error] = "Could not add task at this time." 
redirect_to list_url(@list) 
    end 
end 

def complete 
    @task = @list.tasks.find(params[:id]) 
    @task.completed = true 
    @task.save 
    redirect_to list_url(@list) 
end 

private 
    def find_list 
    @list = List.find(params[:list_id]) 
    end 

그리고 (오류가 발생)에 show.html.erb :

,
<%= button_to "Complete", complete_task_path(@list.id,task.id) %> 

누군가 내가 잘못하고있는 것을 말해 줄 수 있습니까? 문제의 원인은 무엇

+0

경로를 올바르게 정의하지 않았습니다. 어쨌든 complete_task_path (task.id, : list_id => @ list.id) 여야한다고 생각합니다. 실제로 레일을 알아낼 정도로 똑똑하기 때문에 .id 부분을 생략 할 수도 있습니다. – vise

답변

1

는 쇼보기에서 task.id이 당신의 경로에있는 동안, 전무를 반환한다는 것입니다 :

match 'lists/:list_id/tasks/:id/complete' => 'tasks#complete', :as => :complete_task 

은 URL 패턴과 일치하기 위해 작업 ID가 필요합니다.

this blog post에서 자세한 내용을 볼 수 있습니다.

+0

대단히 감사합니다! – Dobabeswe