Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.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 迁移Rails 6.1,ArgumentError异常:参数数量错误 环境:_Ruby On Rails_Ruby_Activerecord - Fatal编程技术网

Ruby on rails 迁移Rails 6.1,ArgumentError异常:参数数量错误 环境:

Ruby on rails 迁移Rails 6.1,ArgumentError异常:参数数量错误 环境:,ruby-on-rails,ruby,activerecord,Ruby On Rails,Ruby,Activerecord,Ruby:2.6.0 Rails:6.1.0 脚本: 在我的项目中,我有一个模型产品,如下所示: # encoding: utf-8 class Product < ApplicationRecord validates_presence_of :name ... default_scope -> { order("name ASC")} end 我看到在Rails 6.1中,default\u scope的行为通过添加**all\u

Ruby:2.6.0

Rails:6.1.0

脚本: 在我的项目中,我有一个模型
产品
,如下所示:

# encoding: utf-8
class Product < ApplicationRecord
  
  validates_presence_of :name
  ...

  default_scope -> { order("name ASC")}
  
end
我看到在Rails 6.1中,
default\u scope
的行为通过添加
**all\u querys**
而改变,但我不明白。这与我无关


任何一个都有相同的问题?

您是否通过任何更改覆盖初始化方法?或者用一块宝石覆盖它?如果删除
默认\u范围
是否有效?你的
ApplicationRecord
类中有什么?你也可以指定你的活动记录gem版本,也许可以从
rails c
而不是从
byebug
中尝试一下,看看会发生什么?@Mshka,如果我删除了默认范围,
Product.new
它可以工作。在
ApplicationRecord
中,只有
self.abstract\u class=true
。Activerecord版本:6.1.0。rails控制台下也存在同样的问题。我无法重现您的错误。您的描述中一定遗漏了一些关键的gem/override。只有(!!!!)上面显示的行会发生这种情况吗?尝试暂时删除模型中的所有其他内容。@TomLord,您是否可以使用一些有用的工具来显示默认范围为
覆盖
定义原点
的所有位置?
(byebug) Product.new
*** ArgumentError Exception: wrong number of arguments (given 2, expected 1)