2015-09-10 42 views
-2

標題說這一切,我不明白爲什麼我得到這個錯誤。沒有路線匹配[刪除](如何建立一個在軌道4 YouTube的教程做的應用程序)

待辦事項控制器:

class TodoListsController < ApplicationController 
    before_action :set_todo_list, only: [:show, :edit, :update, :destroy] 


    def index 
    @todo_lists = TodoList.all 
    end 


    def show 
    end 


    def new 
    @todo_list = TodoList.new 
    end 


    def edit 
    end 


    def create 
    @todo_list = TodoList.new(todo_list_params) 

    respond_to do |format| 
     if @todo_list.save 
     format.html { redirect_to @todo_list, notice: 'Todo list was successfully created.' } 
     format.json { render :show, status: :created, location: @todo_list } 
     else 
     format.html { render :new } 
     format.json { render json: @todo_list.errors, status: :unprocessable_entity } 
     end 
    end 
    end 


    def update 
    respond_to do |format| 
     if @todo_list.update(todo_list_params) 
     format.html { redirect_to @todo_list, notice: 'Todo list was successfully updated.' } 
     format.json { render :show, status: :ok, location: @todo_list } 
     else 
     format.html { render :edit } 
     format.json { render json: @todo_list.errors, status: :unprocessable_entity } 
     end 
    end 
    end 


    def destroy 
    @todo_list.destroy 
    respond_to do |format| 
     format.html { redirect_to root_url, notice: 'Todo list was successfully destroyed.' } 
     format.json { head :no_content } 
    end 
    end 

    private 

    def set_todo_list 
     @todo_list = TodoList.find(params[:id]) 
    end 


    def todo_list_params 
     params.require(:todo_list).permit(:title, :description) 
    end 
end 
+0

你在視圖中傳遞給link_to的是什麼? – madcow

+0

這個問題實際上是在我添加刪除選項後開始的。 – TheMansa

回答

1

確保您routes.rb文件中有這樣的事情

resources :todo_lists 

delete "/todo_lists/:id" => "todo_lists#destroy" 

鏈接應該

<%= link_to 'Delete', todo_list_path(@todo_list), method: :delete, data: { confirm: "Are you sure?" } %> 
+0

它在那裏。 'Rails.application.routes.draw做 資源:todo_lists做 資源:todo_items做 成員做 補丁:完整 結束 結束 結束 根 「todo_lists#指數」 結束 ' – TheMansa

+0

試更新你的鏈接路徑到'todo_list_path' –