Forum: Ruby on Rails How can I set default order in Model.rb?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A1b97dafea62b11e7b3bef338ce3fe83?d=identicon&s=25 Billy Hsu (cfc)
on 2009-03-10 04:23
(Received via mailing list)
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.
[code]
Bulletin.all #=> Same as: Bulletin.find(:all, {:order => "publish_at
DESC"})
[/code]

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
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2009-03-10 04:33
(Received via mailing list)
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
A1b97dafea62b11e7b3bef338ce3fe83?d=identicon&s=25 Billy Hsu (cfc)
on 2009-03-10 04:42
(Received via mailing list)
Thank you, Philip :)

On Tue, Mar 10, 2009 at 11:32 AM, Philip Hallstrom <philip@pjkh.com>
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
This topic is locked and can not be replied to.