views:

77

answers:

3

afternoon all.

i am working on a project written on rails 2.1

in newer versions we can use a rather cool method to create a default scope like so

  default_scope :order => 'title ASC'

how can the same/similar effect be achieved without upgrading the rails version?

A: 

You might be able to use the utility_scopes gem to do this for you.

Steve Weet
A: 

The has_finder gem became named scopes in more recent versions of Rails. But I don't think it does default scopes.

The global_scope plugin found here seems to do what you want.

EmFi
+3  A: 

You might consider back-porting the default_scope functionality into your project.

I think this is the commit that added default_scope.

You shoujld only need to make the changes shown in active_record/base.rb. The other parts are documentation and test, which you should consider adding but are not essential.

Mike Woodhouse