我收到以下错误:
Routing Error
No route matches {:controller=>"tasks", :action=>"complete", :list_id=>1, :id=>nil}
Try running rake routes for more information on available routes.
这就是我的 routes.rb 文件中的内容:
resources :lists do
resources :tasks
end
match 'lists/:list_id/tasks/:id/complete' => 'tasks#complete', :as => :complete_task
root :to => 'lists#index'
在我的任务控制器中:
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) %>
有人可以告诉我我做错了什么吗?