2015-10-24 15:34:43 +08:00
|
|
|
|
class BlogsController < ApplicationController
|
2016-01-07 15:09:09 +08:00
|
|
|
|
before_filter :find_blog,:except => [:index,:create,:new,:set_homepage, :cancel_homepage]
|
2015-10-24 15:34:43 +08:00
|
|
|
|
before_filter :find_user
|
|
|
|
|
def index
|
|
|
|
|
@article = BlogComment.new
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html {render :layout=>'new_base_user'}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
def create
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
def new
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
def show
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
def update
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
def destory
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
def edit
|
|
|
|
|
|
|
|
|
|
end
|
2016-01-07 15:09:09 +08:00
|
|
|
|
|
|
|
|
|
def set_homepage
|
|
|
|
|
@blog = Blog.find(params[:id])
|
|
|
|
|
@blog.update_attribute(:homepage_id, params[:article_id])
|
|
|
|
|
redirect_to user_blogs_path(params[:user_id])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def cancel_homepage
|
|
|
|
|
@blog = Blog.find(params[:id])
|
|
|
|
|
@blog.update_attribute(:homepage_id, nil)
|
|
|
|
|
redirect_to user_blogs_path(params[:user_id])
|
|
|
|
|
end
|
2015-10-24 15:34:43 +08:00
|
|
|
|
private
|
|
|
|
|
def find_blog
|
2015-10-26 10:54:27 +08:00
|
|
|
|
if params[:blog_id]
|
|
|
|
|
@blog = Blog.find(params[:blog_id])
|
|
|
|
|
else
|
|
|
|
|
render_404
|
|
|
|
|
end
|
2015-10-24 15:34:43 +08:00
|
|
|
|
if @blog.nil?
|
|
|
|
|
#如果某个user的blog不存在,那么就创建一条
|
|
|
|
|
@blog = Blog.create(:name=>User.find(params[:id]).realname ,
|
|
|
|
|
:description=>'',
|
|
|
|
|
:author_id=>params[:id])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def find_user
|
|
|
|
|
@user = User.find(params[:user_id])
|
|
|
|
|
end
|
|
|
|
|
end
|