How can I set default order in Model.rb?


#1

Hi, all
How can I set a default order in a model.rb?

For an instance, I have a model called “Bulletin”
I want all query with ‘find’ method return records by ordered.

Bulletin.all #=> Same as: Bulletin.find(:all, {:order => "publish_at 
DESC"})

Should I write a method to do that? Or I can set something in the
bulletin
model?

Thanks!


[73, 32, 108, 111, 118, 101, 32, 121, 111, 117, 32, 115, 111, 32, 109,
117,
99, 104, 33].map{|c| c.chr}.join

Only two surfaces of a box:
http://blog.pixnet.net/zusocfc


#2

On Mar 9, 2009, at 8:22 PM, CFC wrote:

Should I write a method to do that? Or I can set something in the
bulletin
model?

Thanks!

It depends on what version of Rails you’re running. 2.3 has it built
in. Prior to that there is a plugin. Go to agilewebdevelopment.com/
plugins and search for “default order”. Or read the release notes for
2.3.

-philip


#3

Thank you, Philip :slight_smile:

On Tue, Mar 10, 2009 at 11:32 AM, Philip H. removed_email_address@domain.invalid
wrote:

Bulletin.all #=> Same as: Bulletin.find(:all, {:order => "publish_at
in. Prior to that there is a plugin. Go to agilewebdevelopment.com/
plugins and search for “default order”. Or read the release notes for
2.3.

-philip


[73, 32, 108, 111, 118, 101, 32, 121, 111, 117, 32, 115, 111, 32, 109,
117,
99, 104, 33].map{|c| c.chr}.join

Only two surfaces of a box:
http://blog.pixnet.net/zusocfc