Class: Enki::Admin::PostsController

Inherits:
BaseController show all
Defined in:
app/controllers/enki/admin/posts_controller.rb

Instance Method Summary collapse

Methods included from HostHelper

#render_enki

Methods included from UrlHelper

#author_link, #post_comments_path, #post_path

Methods included from TagHelper

#linked_tag_list

Methods included from PostsHelper

#more_content?

Methods included from PageTitleHelper

#archives_title, #html_title, #page_title, #post_title, #posts_title

Methods included from NavigationHelper

#category_links_for_navigation, #class_for_tab, #page_links_for_navigation

Methods included from FormHelper

#admin_form_for

Methods included from DateHelper

#format_comment_date, #format_month, #format_post_date

Methods included from Enki::ApplicationHelper

#author, #comments?, #format_comment_error, #paginated, #tags?

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/enki/admin/posts_controller.rb', line 14

def create
  @post = build_post(post_params)
  if @post.save
    respond_to do |format|
      format.html {
        flash[:notice] = "Created post '#{@post.title}'"
        redirect_to(enki.admin_post_path(@post))
      }
    end
  else
    respond_to do |format|
      format.html { render :action => 'new', :status => :unprocessable_entity }
    end
  end
end

#destroyObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/enki/admin/posts_controller.rb', line 67

def destroy
  undo_item = @post.destroy_with_undo

  respond_to do |format|
    format.html do
      flash[:notice] = "Deleted post '#{@post.title}'"
      redirect_to admin_posts_path
    end
    format.json {
      render :json => {
        :undo_path    => undo_admin_undo_item_path(undo_item),
        :undo_message => undo_item.description,
        :post         => @post.attributes
      }
    }
  end
end

#indexObject



6
7
8
9
10
11
12
# File 'app/controllers/enki/admin/posts_controller.rb', line 6

def index
  respond_to do |format|
    format.html {
      @posts = Post.order("published_at DESC").paginated(params)
    }
  end
end

#newObject



53
54
55
# File 'app/controllers/enki/admin/posts_controller.rb', line 53

def new
  @post = build_post
end

#previewObject



57
58
59
60
61
62
63
64
65
# File 'app/controllers/enki/admin/posts_controller.rb', line 57

def preview
  @post = Post.build_for_preview(post_params)

  respond_to do |format|
    format.js {
      render :partial => @post
    }
  end
end

#showObject



45
46
47
48
49
50
51
# File 'app/controllers/enki/admin/posts_controller.rb', line 45

def show
  respond_to do |format|
    format.html {
      render :partial => @post if request.xhr?
    }
  end
end

#updateObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/enki/admin/posts_controller.rb', line 30

def update
  if @post.update_attributes(post_params)
    respond_to do |format|
      format.html {
        flash[:notice] = "Updated post '#{@post.title}'"
        redirect_to(enki.admin_post_path(@post))
      }
    end
  else
    respond_to do |format|
      format.html { render :action => 'show', :status => :unprocessable_entity }
    end
  end
end