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
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. [email protected] wrote:
Thanks,
Jason
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
–
Cody F.
http://www.codyfauser.com