我升级到Rails 5,启动服务器后必须加载登录表单。然后发生此错误:
ArgumentError - invalid argument: nil.:
activerecord (5.0.0.1) lib/active_record/relation/spawn_methods.rb:36:in `merge'
activerecord (5.0.0.1) lib/active_record/scoping/default.rb:119:in `block (2 levels) in build_default_scope'
activerecord (5.0.0.1) lib/active_record/scoping/default.rb:117:in `block in build_default_scope'
activerecord (5.0.0.1) lib/active_record/scoping/default.rb:141:in `evaluate_default_scope'
activerecord (5.0.0.1) lib/active_record/scoping/default.rb:116:in `build_default_scope'
activerecord (5.0.0.1) lib/active_record/scoping/named.rb:33:in `default_scoped'
activerecord (5.0.0.1) lib/active_record/scoping/named.rb:28:in `all'
activerecord (5.0.0.1) lib/active_record/scoping.rb:24:in `scope_attributes'
activerecord (5.0.0.1) lib/active_record/scoping.rb:36:in `populate_with_current_scope_attributes'
activerecord (5.0.0.1) lib/active_record/scoping.rb:43:in `initialize_internals_callback'
activerecord (5.0.0.1) lib/active_record/core.rb:317:in `initialize'
activerecord (5.0.0.1) lib/active_record/inheritance.rb:65:in `new'
devise (4.2.0) app/controllers/devise/sessions_controller.rb:9:in `new'
这似乎来自Devise我想? 搜索后我发现有人犯了同样的错误:
Turns it it was a gem which behind the scenes was attempting to do default_scope { nil }, looks like someone implemented protection against that (since it shouldn't really work)
我该怎么办?
答案 0 :(得分:0)
nil
不再作为merge
参数有效,因为该方法需要一个ActiveRecord_Relation
类的参数。
此问题与this PR on Rails有关。 这是resolution commit。
为避免此错误:
merge
属性,并仅在它不为null时附加它。ActiveRecord_Relation
传递给merge
,例如,<ARModel>.all
而不是nil(如果实际参数为nil)。