Forum: Ruby on Rails put the list of posts in descending order

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.
Dcf093a36c8a7e286dbefe10454813e1?d=identicon&s=25 Ishara Gunathilake (Guest)
on 2008-11-04 07:13
(Received via mailing list)
hi,i have a table called blogs which include
t.column :user_id, :integer
t.column :post_id, :integer
t.column:title, :string
t.column:body, :string

and i have a seperate form to fill the title and post field,i can
display the title and body in a page.but the records are displayed in
the ascending order,that means the last i last i entered is displayed
first
..but i want to display it in descending order,,,that mean the newly
entered
record should display at the top of the page,,,please can anyone send me
the code to do this
2d8132658d56e51f19ace1c68e48b6aa?d=identicon&s=25 Thorsten Mueller (thorsten)
on 2008-11-04 11:18
(Received via mailing list)
> the last i last i entered is displayed first
> ..but i want to display it in descending order,,,that mean the newly entered
> record should display at the top of the page

Isn't that the same? Last/newly entered display first?

anyway, in the examples replace DESC by ASC to revert order

if your model has a created_at column:
@blogs = Blog.find(:all, :order => "created_at DESC")

if you don't have the created_at col (you should), sort by id:
@blogs = Blog.find(:all, :order => "id DESC")
Dcf093a36c8a7e286dbefe10454813e1?d=identicon&s=25 Ishara Gunathilake (Guest)
on 2008-11-04 15:22
(Received via mailing list)
thankx....il try

2008/11/4 Thorsten Müller <thorsten@80beans.com>
This topic is locked and can not be replied to.