default scope in older rails versions

245 Views Asked by At

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?

3

There are 3 best solutions below

0
On

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

0
On

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.

0
On

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.