![](/img/trans.png)
[英]after upgrading to rails 5.1.7 have an error ArgumentError: invalid argument: nil
[英]invalid argument: nil error after upgrading to Rails 5
我已升級到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)
我該怎么辦?
nil
不再有效作為merge
參數,因為該方法需要一個ActiveRecord_Relation
類的參數。
此問題與該Rails PR有關 。 這是在導軌上的分辨率提交 。
為避免此錯誤:
merge
屬性,並僅在不為null時附加它。 ActiveRecord_Relation
進行merge
,例如,如果實際參數為nil,則使用<ARModel>.all
而不是nil。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.