# Setting "defaults" on AR finds

**URL:** <https://www.ruby-forum.com/t/setting-defaults-on-ar-finds/110260>\
**Category:** Rails\
**Created:** [July 24, 2007, 7:03pm UTC](https://www.ruby-forum.com/t/setting-defaults-on-ar-finds/110260 "2007-07-24T19:03:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [July 24, 2007, 7:03pm UTC](https://www.ruby-forum.com/t/setting-defaults-on-ar-finds/110260/1 "2007-07-24T19:03:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [July 24, 2007, 7:58pm UTC](https://www.ruby-forum.com/t/setting-defaults-on-ar-finds/110260/2 "2007-07-24T19:58:26Z")

</div>

> 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](http://agilewebdevelopment.com/plugins/search?search=scope)
