Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

limit documents, and order by desc

  • Loading branch information...
commit 98d83fdff01b502e237a2bab732e3cd58c52f9ea 1 parent 6b0b175
James Yu authored committed
View
2  app/controllers/documents_controller.rb
@@ -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
3  app/models/document.rb
@@ -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 = {})
View
4 db/migrate/20110130205848_create_documents.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.