次のエラーが表示されます。
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'
私のtasks_controllerで:
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) %>
誰かが私が間違っていることを教えてもらえますか?