wblog/app/controllers/blogs_controller.rb

21 lines
659 B
Ruby
Raw Normal View History

2012-06-24 06:51:18 +08:00
# encoding : utf-8
2012-06-23 09:42:37 +08:00
class BlogsController < ApplicationController
def index
2014-03-29 21:59:15 +08:00
@newest = Post.desc(:created_at).to_a.first
@recent = Post.desc(:created_at).to_a[1..2]
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
@post = Post.find(params[:id])
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
2012-06-23 09:42:37 +08:00
end
end