博客排序采用创建时倒序

This commit is contained in:
yafei Lee 2012-06-25 08:16:34 +08:00
parent 4b808d1123
commit 404445f3af
5 changed files with 15 additions and 5 deletions

View File

@ -1,5 +1,5 @@
GEM
remote: http://ruby.taobao.org/
remote: http://rubygems.org/
specs:
actionmailer (3.2.6)
actionpack (= 3.2.6)

View File

@ -3,14 +3,14 @@ class BlogsController < ApplicationController
def index
type = params[:type]
if type or type == ""
@posts = Post.where(type: map[type])
@posts = Post.where(type: map[type]).order(:created_at => :desc )
else
@posts = Post.all
@posts = Post.all.order(:created_at => :desc )
end
end
def rss
@posts = Post.all.limit(10)
@posts = Post.all.order(:created_at => :desc).limit(10)
render :layout=>false
response.headers["Content-Type"] = "application/xml; charset=utf-8"
end

View File

@ -4,6 +4,7 @@ class Post
LIFE = "生活"
CREATOR = "创业"
include Mongoid::Document
include Mongoid::Timestamps
field :title, :type => String
field :content, :type => String
field :type, :type=> String

View File

@ -11,6 +11,6 @@ describe Admin::PostsController do
puts 'hello world'
```
EOF
response.body.should == "<p><code>ruby\nputs &#39;hello world&#39;\n</code></p>\n"
response.body.should == "<p><code>ruby<br>\nputs &#39;hello world&#39;<br>\n</code></p>\n"
end
end

View File

@ -2,4 +2,13 @@ require 'spec_helper'
describe BlogsController do
it 'index should get by order desc' do
a = Post.new(title: '123', content: '123'*20, type: Post::TECH)
a.save!
sleep 1
b = Post.new(title: '1234', content: '123'*20,type: Post::TECH)
b.save!
get :index
assigns[:posts][1].title.should == a.title
end
end