-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,但我再次得到相同的錯誤。
你能分享你的模型代碼嗎? –
'Todo'是模型(類)還是模塊?巨大差距。聽起來像你可能已經將你的模型定義爲一個模塊。 – MrDanA
顯示您的Todo課程(模型) – nobilik