Class: Blogo::Admin::PostsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/blogo/admin/posts_controller.rb', line 12

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

  if service.create!
    @post = service.post
    flash[:notice] = "The post is created"
    redirect_to blogo_admin_posts_path
  else
    @post = service.post
    render 'new'
  end
end

#destroyObject



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

def destroy
  post = Blogo::Post.find(params[:id])
  Blogo::DestroyPostService.new(post).destroy!

  flash[:notice] = "The post is removed"
  redirect_to blogo_admin_posts_path
end

#editObject



25
26
27
# File 'app/controllers/blogo/admin/posts_controller.rb', line 25

def edit
  @post = Blogo::Post.find(params[:id])
end

#indexObject



4
5
6
# File 'app/controllers/blogo/admin/posts_controller.rb', line 4

def index
  @posts = Blogo::Post.all
end

#newObject



8
9
10
# File 'app/controllers/blogo/admin/posts_controller.rb', line 8

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

#previewObject



49
50
51
52
53
54
55
# File 'app/controllers/blogo/admin/posts_controller.rb', line 49

def preview
  @post = Blogo::PreviewPostService.new(blogo_current_user, post_params).preview

  @meta = {title: @post.title }
  @tags = Blogo::Tag.all
  render 'blogo/posts/show', layout: 'blogo/blog'
end

#updateObject



29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/blogo/admin/posts_controller.rb', line 29

def update
  @post = Blogo::Post.find(params[:id])
  service = Blogo::UpdatePostService.new(@post, post_params)

  if service.update!
    flash[:notice] = "The post is updated"
    redirect_to blogo_admin_posts_path
  else
    render 'edit'
  end
end