Skip to content
This repository
tree: 226cc2a597
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 58 lines (45 sloc) 1.273 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
# coding: utf-8
class Cpanel::PostsController < Cpanel::ApplicationController

  def index
    @posts = Post.unscoped.desc(:_id).includes(:user).paginate :page => params[:page], :per_page => 30
  end

  def show
    @post = Post.unscoped.find(params[:id])

    drop_breadcrumb("文章")

  end

  def new
    @post = Post.new
    drop_breadcrumb("文章")
    drop_breadcrumb("创建")
  end

  def edit
    @post = Post.unscoped.find(params[:id])
    @post.tag_list = @post.tags.join(", ")

  end

  def create
    @post = Post.new(params[:post])
    if @post.save
      redirect_to(cpanel_posts_path, :notice => 'Post was successfully created.')
    else
      render :action => "new"
    end
  end

  def update
    @post = Post.unscoped.find(params[:id])
    @post.title = params[:post][:title]
    @post.body = params[:post][:body]
    @post.tag_list = params[:post][:tag_list]
    @post.user_id = params[:post][:user_id]
    @post.state = params[:post][:state]

    if @post.update_attributes(params[:post])
      redirect_to(cpanel_posts_path, :notice => 'Post was successfully updated.')
    else
      render :action => "edit"
    end
  end

  def destroy
    @post = Post.unscoped.find(params[:id])
    @post.destroy

    redirect_to(cpanel_posts_path)
  end
end
Something went wrong with that request. Please try again.