2012-06-24 06:51:18 +08:00
|
|
|
# encoding : utf-8
|
2012-06-23 09:42:37 +08:00
|
|
|
class BlogsController < ApplicationController
|
2014-04-01 17:09:35 +08:00
|
|
|
|
2012-06-23 09:42:37 +08:00
|
|
|
def index
|
2014-04-01 10:20:58 +08:00
|
|
|
@newest = Post.desc(:created_at).first
|
2014-04-02 13:08:18 +08:00
|
|
|
@recent = Post.desc(:created_at).to_a[1..3]
|
2014-12-26 03:42:02 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json
|
|
|
|
end
|
2012-06-23 09:42:37 +08:00
|
|
|
end
|
|
|
|
|
2012-06-25 00:09:44 +08:00
|
|
|
def rss
|
2012-06-25 08:16:34 +08:00
|
|
|
@posts = Post.all.order(:created_at => :desc).limit(10)
|
2012-06-25 00:09:44 +08:00
|
|
|
render :layout=>false
|
|
|
|
response.headers["Content-Type"] = "application/xml; charset=utf-8"
|
|
|
|
end
|
|
|
|
|
2012-06-23 09:42:37 +08:00
|
|
|
def show
|
2012-06-23 12:07:24 +08:00
|
|
|
@post = Post.find(params[:id])
|
2014-03-31 23:56:19 +08:00
|
|
|
@post.visited
|
2014-03-31 14:45:36 +08:00
|
|
|
@prev = Post.where(:created_at.lt => @post.created_at).desc(:created_at).where(:id.ne => @post.id).first
|
|
|
|
@next = Post.where(:created_at.gt => @post.created_at).asc(:created_at).where(:id.ne => @post.id).first
|
2014-03-30 16:16:30 +08:00
|
|
|
@comments = @post.comments
|
2014-12-26 01:58:26 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json
|
|
|
|
end
|
2012-06-23 09:42:37 +08:00
|
|
|
end
|
2014-04-01 18:24:54 +08:00
|
|
|
|
|
|
|
def edit
|
|
|
|
@post = Post.find( params[:id] )
|
|
|
|
redirect_to edit_admin_post_path(@post)
|
|
|
|
end
|
2012-06-23 09:42:37 +08:00
|
|
|
end
|