Ruby on rails Ruby on Rail s:获得NoMethodError 错误 我的待办事项\u项目\u控制器.rb 类TodoItemsController
尝试将您的Ruby on rails Ruby on Rail s:获得NoMethodError 错误 我的待办事项\u项目\u控制器.rb 类TodoItemsController,ruby-on-rails,ruby,Ruby On Rails,Ruby,尝试将您的待办事项参数更改为: class TodoItemsController < ApplicationController def index @todo_list = TodoList.find(params[:todo_list_id]) end def new @todo_list = TodoList.find(params[:todo_list_id]) @todo_item = @todo_list.todo_items.new
待办事项参数更改为:
class TodoItemsController < ApplicationController
def index
@todo_list = TodoList.find(params[:todo_list_id])
end
def new
@todo_list = TodoList.find(params[:todo_list_id])
@todo_item = @todo_list.todo_items.new
end
def new
@todo_list = TodoList.find(params[:todo_list_id])
@todo_item = @todo_list.todo_items.new(todo_item_params)
if @todo_item.save
flash[:success] = "Added todo list item."
redirect_to todo_list_todo_item_path
else
flash[:error] = "There was a problem adding that todo list item."
render action: :new
end
end
private
def todo_item_params
params[:todo_item].permit(:content)
end
end
我认为这一错误有两个原因:
第一个是在您的todo_item_params
方法中。您必须按照pavan的建议进行更改,例如:
private
def todo_item_params
params.require(:todo_item).permit(:content)
end
第二个问题是控制器中有两个新的方法。没有创建
、保存
和更新
方法。检查参数[:待办事项]它是无
您的问题是什么?无法消除错误#尝试过但仍然出现错误失败/错误:单击链接“新建待办事项”ActionController::ParameterMissing:param缺失或值为空:todo_项#./app/controllers/todo_项(controller.rb:25:intodo_项)./app/controllers/todo_项(controller.rb:13:in
new'./spec/features/todo_项/create(spec.rb:15:in`block(2层)in'@RohitYadav.你的表单看起来怎么样?在提交问题中的表单时,是否可以发布日志中生成的参数?@RohitYadav请使用表格代码和日志中生成的参数编辑您的问题
class TodoItemsController < ApplicationController
def index
@todo_list = TodoList.find(params[:todo_list_id])
end
def new
@todo_list = TodoList.find(params[:todo_list_id])
@todo_item = @todo_list.todo_items.new
end
def new
@todo_list = TodoList.find(params[:todo_list_id])
@todo_item = @todo_list.todo_items.new(todo_item_params)
if @todo_item.save
flash[:success] = "Added todo list item."
redirect_to todo_list_todo_item_path
else
flash[:error] = "There was a problem adding that todo list item."
render action: :new
end
end
private
def todo_item_params
params[:todo_item].permit(:content)
end
end
private
def todo_item_params
params.require(:todo_item).permit(:content)
end
def todo_item_params
params.require(:todo_item).permit(:content)
end