Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Ruby on Rail s:获得NoMethodError 错误 我的待办事项\u项目\u控制器.rb 类TodoItemsController_Ruby On Rails_Ruby - Fatal编程技术网

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:in
todo_项)./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