博客排序采用创建时倒序
This commit is contained in:
parent
4b808d1123
commit
404445f3af
|
@ -1,5 +1,5 @@
|
|||
GEM
|
||||
remote: http://ruby.taobao.org/
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
actionmailer (3.2.6)
|
||||
actionpack (= 3.2.6)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -11,6 +11,6 @@ describe Admin::PostsController do
|
|||
puts 'hello world'
|
||||
```
|
||||
EOF
|
||||
response.body.should == "<p><code>ruby\nputs 'hello world'\n</code></p>\n"
|
||||
response.body.should == "<p><code>ruby<br>\nputs 'hello world'<br>\n</code></p>\n"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue