Forum: Ruby on Rails Setting a default order for a model?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
D2b2017098da3e2fd1cdcfbb72ecdbfb?d=identicon&s=25 Jason Edgecombe (Guest)
on 2006-01-31 17:45
(Received via mailing list)

I'm using a room model throughout my code. I keep doing the following:
    @rooms = Room.find(:all, :order => ', room_number',
:include => :building)

I have to copy this into several of my controllers and I feel that I'm
violating the DRY principle. Can I set this as the default order in my
model? If so, how would I do that?

2ccb2f7699267d258faaafce4ee997df?d=identicon&s=25 Cody Fauser (Guest)
on 2006-01-31 18:16
(Received via mailing list)

You could add a static method to your Room model:

def self.find_all_include_building
  find(:all, :order => ', room_number',  :include =>

Then just:
@rooms = Room.find_all_include_building

On 1/31/06, Jason Edgecombe <> wrote:
> Thanks,
> Jason
> _______________________________________________
> Rails mailing list

Cody Fauser
This topic is locked and can not be replied to.