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.
Jason E. (Guest)
on 2006-01-31 18: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?

Cody F. (Guest)
on 2006-01-31 19: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 E. <removed_email_address@domain.invalid> wrote:
> Thanks,
> Jason
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid

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