2016-01-21 49 views
-2

所以,我得到這個錯誤從todo_controller.rb未定義的方法',其中」爲TODO:模塊

class TodoController < ApplicationController 
    def index 
    @todos = Todo.where(done: false) 
    @todone = Todo.where(done: true) 
    end 

    def new 
    @todo = Todo.new 
    end 

    def todo_params 
    params.require(:todo).permit(:name, :done) 
    end 

    def create 
    @todo = Todo.new(todo_params) 
    if @todo.save 
     redirect_to todo_index_path, :notice => "Your todo item was created!" 
    else 
     render 'new' 
    end 
    end 

    def update 
    @todo = Todo.find(params[:id]) 
    if @todo.update_attribute(:done, true) 
     redirect_to todo_index_path, :notice => "Your todo item was marked as done!" 
    else 
     redirect_to todo_index_path, :notice => "Your todo item wasn't marked as done!" 
    end 
    end 

    def destroy 
    @todo = Todo.find(params[:id]) 
    @todo.destroy 
    redirect_to todo_index_path, :notice => "Your todo task has been deleted!" 
    end 
end 

我GOOGLE了它,並發現有應該是具有相同名稱的模塊。我發現它config/application.rb,我將其更改爲模塊todoo,但我再次得到相同的錯誤。

+0

你能分享你的模型代碼嗎? –

+2

'Todo'是模型(類)還是模塊?巨大差距。聽起來像你可能已經將你的模型定義爲一個模塊。 – MrDanA

+0

顯示您的Todo課程(模型) – nobilik

回答

0

我只是完全重新編寫了應用程序,它工作。我想我自己做了一些應該由Rails自動完成的事情,以及它出錯的地方。

+0

Rails生成器是你的朋友。 :-) – jeffdill2

相關問題