Setting "defaults" on AR finds


#1

let’s say i have a Category model. every time i pull the categories, i
am writing something along the lines of @categories =
Category.find(:all, :order => :position)

is there a way to put something in the model so that any time i find
categories with Category.find(:all), it will automatically sort by the
position column unless i specify otherwise? i would like to be able to
change something like that in one place instead of passing the same
parameters to it every time.

i did add something like this to the model which also works:

def self.order_by_position
find(:all, :order => :position)
end

so that i can just do Category.order_by_position but was just
wondering if there’s a better way.


#2

i did add something like this to the model which also works:

def self.order_by_position
find(:all, :order => :position)
end

so that i can just do Category.order_by_position but was just
wondering if there’s a better way.

One of these might do it…

http://agilewebdevelopment.com/plugins/search?search=scope