Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.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 表单中的第一个参数不能包含nil或为空ArgumentError in Productcategories#new_Ruby On Rails - Fatal编程技术网

Ruby on rails 表单中的第一个参数不能包含nil或为空ArgumentError in Productcategories#new

Ruby on rails 表单中的第一个参数不能包含nil或为空ArgumentError in Productcategories#new,ruby-on-rails,Ruby On Rails,我得到这个错误: ActionView::Template::Error(表单中的第一个参数不能包含nil 或为空): 7: 新增商品分类 8: 9: 10: 11: 12: 13:app/views/productcategories/new.html.erb:10:in `_应用程序\视图\产品类别\新的\ html \ erb\ uuuuuuuuu593308190794838703\ uu70267444710660' 翻译 /Users/liupengfei

我得到这个错误:

ActionView::Template::Error(表单中的第一个参数不能包含nil 或为空): 7: 新增商品分类 8: 9: 10: 11: 12: 13:app/views/productcategories/new.html.erb:10:in `_应用程序\视图\产品类别\新的\ html \ erb\ uuuuuuuuu593308190794838703\ uu70267444710660' 翻译 /Users/liupengfei/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.2/lib/action\u dispatch/middleware/templates/rescues/template\u error.html.erb 内部救援/布局渲染 /Users/liupengfei/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.2/lib/action\u dispatch/middleware/templates/rescues//u source.html.erb 提供 /Users/liupengfei/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.2/lib/action\u dispatch/middleware/templates/rescues//u source.html.erb (4.1ms)渲染 /Users/liupengfei/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.2/lib/action\u dispatch/middleware/templates/rescues//u trace.html.erb /Users/liupengfei/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.2/lib/action\u dispatch/middleware/templates/rescues//u trace.html.erb(2.1ms)渲染 /Users/liupengfei/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.2/lib/action\u dispatch/middleware/templates/rescues//u request\u and\u response.html.erb

这是我的源代码:

def new
  @productCategory = ProductCategory.new
end

def create
  @productCategory = ProductCategory.new(ProductCategory_params)

  if @ProductCategory.save
    redirect_to productcategories_path
  else
    render :new
  end
end

请帮助我解决此问题。

您在表单中使用了错误的实例变量名

def new
  @productCategory = ProductCategory.new
end
改变

<%= form_for @productCategories do |f| %> <- 错误在这里 ->


编辑:

对于您得到的错误,您需要手动传递路径

<%= form_for @productCategory, url: productcategories_path do |f| %> <- 错误在这里 ->

Productcategories中的命名错误#新显示/用户/刘鹏飞/我的项目/我的毕设/scht/app/views/productcategories/new.html.erb,其中第10行出现:未定义的方法“product#u categories#u path”,您的意思是?productcategories\u path productcategories\u path productcategories\u url提取源(第10行附近):8 9 10 11 12 13
<%= form_for @productCategory, url: productcategories_path do |f| %> <- 错误在这里 ->