Setting a default order for a model?


#1

Hi,

I’m using a room model throughout my code. I keep doing the following:
@rooms = Room.find(:all, :order => ‘buildings.name, 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?

Thanks,
Jason


#2

Jason,

You could add a static method to your Room model:

def self.find_all_include_building
find(:all, :order => ‘buildings.name, room_number’, :include =>
:building)
end

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
http://lists.rubyonrails.org/mailman/listinfo/rails


Cody F.
http://www.codyfauser.com