1
如何rails4.1.9移动rails2 4和收到错误 - 未定义的方法`with_scope '
AuditArea.send(query_options[:include_retired] ? :with_exclusive_scope : :with_scope) {
# some stuff
}
替换此查询得到错误未定义的方法`with_scope'。
如何rails4.1.9移动rails2 4和收到错误 - 未定义的方法`with_scope '
AuditArea.send(query_options[:include_retired] ? :with_exclusive_scope : :with_scope) {
# some stuff
}
替换此查询得到错误未定义的方法`with_scope'。
with_scope
现在被称为scoping
在较新的Rails版本中。 with_exclusive_scope
现在应该是unscoped
。两种方法都接受一个块,以便您的代码可以正常工作。
有关更多信息,请参阅scoping
和unscoped
的文档。
更新:如果在类本身上调用scoping
方法不起作用。它必须在示波器上被调用(与在裸露模型类上工作的unscoped
相反)。我会首先加入“无害”的范围all
(它选择的所有记录,因此行为方式与裸模型类AuditArea
相同)的选择,这样的send
工作的这两种型号:
AuditArea.all.send(query_options[:include_retired] ? :unscoped : :scoping) {
# ...
}
无范围的作品,但作用域仍然给出错误* NoMethodError异常:未定义的方法'作用域'为 –
你能粘贴完整的错误吗?在Rails 4.1.9中''范围'**是** [定义的方法](https://github.com/rails/rails/blob/v4.1.9/activerecord/lib/active_record/relation.rb#L290)。 – BoraMa
*** NoMethodError异常:未定义方法'范围'为# –