Class: Blogo::Admin::PostsController

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

Overview

Responsible for posts management: creation, editing, deletion, preview.

Instance Method Summary collapse

Instance Method Details

#createObject

POST /admin/posts


18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/blogo/admin/posts_controller.rb', line 18

def create
  service = ::CreatePostService.new(blogo_current_user, post_params)

  if service.create!
    @post = service.post
    flash[:notice] = I18n.translate('blogo.admin.post_created')
    redirect_to blogo_admin_posts_path
  else
    @post = service.post
    render 'new'
  end
end

#destroyObject

DELETE /admin/posts/:id


53
54
55
56
57
58
59
# File 'app/controllers/blogo/admin/posts_controller.rb', line 53

def destroy
  post = ::Post.where(permalink: params[:id]).first!
  ::DestroyPostService.new(post).destroy!

  flash[:notice] = I18n.translate('blogo.admin.post_removed')
  redirect_to blogo_admin_posts_path
end

#editObject

GET /admin/posts/:id/edit


33
34
35
# File 'app/controllers/blogo/admin/posts_controller.rb', line 33

def edit
  @post = ::Post.where(permalink: params[:id]).first!
end

#indexObject

GET /admin/posts


6
7
8
# File 'app/controllers/blogo/admin/posts_controller.rb', line 6

def index
  @posts = ::Post.all
end

#newObject

GET /admin/posts/new


12
13
14
# File 'app/controllers/blogo/admin/posts_controller.rb', line 12

def new
  @post = ::Post.new(published: true)
end

#previewObject

POST /admin/posts/preview


63
64
65
66
67
68
69
70
# File 'app/controllers/blogo/admin/posts_controller.rb', line 63

def preview
  @post         = ::PreviewPostService.new(blogo_current_user, post_params).preview
  @meta         = {title: @post.title }
  @recent_posts = ::Post.published.limit(.config.recent_posts) if .config.recent_posts
  @tags         = ::Tag.all

  render 'blogo/posts/show', layout: 'blogo/blog'
end

#updateObject

PATCH /admin/posts/:id


39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/blogo/admin/posts_controller.rb', line 39

def update
  @post = ::Post.where(permalink: params[:id]).first!
  service = ::UpdatePostService.new(@post, post_params)

  if service.update!
    flash[:notice] = I18n.translate('blogo.admin.post_updated')
    redirect_to blogo_admin_posts_path
  else
    render 'edit'
  end
end