Permalink
Browse files

limit documents, and order by desc

  • Loading branch information...
1 parent 6b0b175 commit 98d83fdff01b502e237a2bab732e3cd58c52f9ea James Yu committed with Feb 1, 2011
@@ -1,6 +1,6 @@
class DocumentsController < ApplicationController
def index
- render :json => Document.all
+ render :json => Document.limited.ordered.all # for the purposes of the demo, just get the last 50 docs
end
def show
View
@@ -1,4 +1,7 @@
class Document < ActiveRecord::Base
+ named_scope :limited, :limit => 50
+ named_scope :ordered, :order => 'created_at desc'
+
attr_accessible :body, :title
def to_json(options = {})
@@ -5,6 +5,10 @@ def self.up
t.text :body
t.timestamps
end
+
+ change_table :documents do |t|
+ t.index :created_at
+ end
end
def self.down

0 comments on commit 98d83fd

Please sign in to comment.