旧版rails中的默认范围

时间:2009-12-07 16:25:50

标签: ruby-on-rails scope find default-scope

下午所有。

我正在研究在rails 2.1上编写的项目

在较新版本中,我们可以使用一种相当酷的方法来创建默认范围,如此

  default_scope :order => 'title ASC'

如何在不升级rails版本的情况下实现相同/类似的效果?

3 个答案:

答案 0 :(得分:3)

您可以考虑将default_scope功能反向移植到项目中。

我认为this is the commit添加了default_scope。

你只需要进行active_record/base.rb中显示的更改。其他部分是文档和测试,您应该考虑添加但不是必需的。

答案 1 :(得分:0)

您可以使用utility_scopes gem为您执行此操作。

答案 2 :(得分:0)

The has_finder gem在更新版本的Rails中成为命名范围。但我不认为它是默认范围。

在这里找到的{p> The global_scope plugin似乎可以做你想要的。