44 lines
795 B
Ruby
44 lines
795 B
Ruby
|
class BlogsController < ApplicationController
|
|||
|
before_filter :find_blog,:except => [:index,:create,:new]
|
|||
|
before_filter :find_user
|
|||
|
def index
|
|||
|
@articls = @user.blog.articles
|
|||
|
@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
|
|||
|
private
|
|||
|
def find_blog
|
|||
|
@blog = Blog.find(params[:blog_id])
|
|||
|
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
|