【发布时间】:2009-12-07 16:25:49
【问题描述】:
下午。
我正在开发一个使用 Rails 2.1 编写的项目
在较新的版本中,我们可以使用一种相当酷的方法来创建这样的默认范围
default_scope :order => 'title ASC'
不升级rails版本如何实现相同/相似的效果?
【问题讨论】:
标签: ruby-on-rails scope find default-scope
下午。
我正在开发一个使用 Rails 2.1 编写的项目
在较新的版本中,我们可以使用一种相当酷的方法来创建这样的默认范围
default_scope :order => 'title ASC'
不升级rails版本如何实现相同/相似的效果?
【问题讨论】:
标签: ruby-on-rails scope find default-scope
您可以考虑将 default_scope 功能反向移植到您的项目中。
我认为 this is the commit 添加了 default_scope。
您只需要进行active_record/base.rb 中显示的更改。其他部分是文档和测试,您应该考虑添加但不是必需的。
【讨论】:
您也许可以使用 utility_scopes gem 为您执行此操作。
【讨论】:
The has_finder gem 在最新版本的 Rails 中成为命名范围。但我认为它没有默认范围。
The global_scope plugin 在这里找到似乎做你想做的事。
【讨论】: