我升级到了Rails5,在启动服务器之后,必须加载登录表单。则会出现以下错误:
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)我该怎么办?
发布于 2019-05-02 21:25:11
nil作为merge参数不再有效,因为该方法需要ActiveRecord_Relation类的参数。
此问题与this PR on Rails相关。这是resolution commit on rails。
要避免此错误,请执行以下操作:
merge属性之前检查它,并且仅当它不为空时才追加它。ActiveRecord_Relation传递给merge,例如,如果实际参数为nil,则使用<ARModel>.all代替nil。https://stackoverflow.com/questions/40376028
复制相似问题