1. Computing

Using Yahoo! UI to Give Your Blog That "Blog Look"

By

9 of 10

The Right Order
Using Yahoo! UI to Give Your Blog That

One thing you may notice is that the index displays the posts backwards. Most blogs display the newest post at the top, while our blog displays the newest post at the bottom. This is easy to fix; simply replace Post.find(:all) in your index action with a query that reverses the order in which the Post objects are retrieved from the database.

# File: posts_controller.rb
def index
<b> @posts = Post.find(:all, :order => 'created_at DESC')</b>

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts }
end
end
  1. About.com
  2. Computing
  3. Ruby
  4. Ruby on Rails
  5. The Right Order

©2014 About.com. All rights reserved.