Class: Admin::PostsController

Inherits:
ApplicationController show all
Defined in:
lib/ecrire/app/controllers/admin/posts_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#posts

Methods inherited from ApplicationController

#current_user, #signed_in?, #url

Instance Method Details

#createObject



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

def create
  @post = Admin::Post.create(title: title_params[:title])

  if @post.errors.any?
    render 'new' and return
  end

  redirect_to url('/admin/posts/:post.id/edit', post: @post)
end

#destroyObject



49
50
51
52
53
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 49

def destroy
  post = Admin::Post.find(params[:id])
  post.destroy
  redirect_to :root
end

#draftsObject



22
23
24
25
26
27
28
29
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 22

def drafts
  posts = Admin::Post.drafted

  posts = posts.search search_posts_params
  @posts = posts.order('posts.created_at DESC').includes(:titles)

  render 'index'
end

#editObject



55
56
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 55

def edit
end

#indexObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 10

def index
  posts = Admin::Post

  posts = posts.search search_posts_params
  @posts = posts.order('posts.created_at DESC').includes(:titles)

  respond_to do |format|
    format.html
    format.js
  end
end

#newObject



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

def new
  @post = Admin::Post.new
end

#publishedObject



31
32
33
34
35
36
37
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 31

def published
  posts = Admin::Post.published

  posts = posts.search search_posts_params
  @posts = posts.order('posts.published_at DESC').includes(:titles)
  render 'index'
end

#showObject



65
66
67
68
69
70
71
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 65

def show
  respond_to do |format|
    format.html do
      render layout: false if request.xhr?
    end
  end
end

#toggleObject



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 73

def toggle
  @post = Admin::Post.find(params[:post_id])
  if @post.published?
    @post.unpublish!
  else
    @post.publish!
  end

  respond_to do |format|
    format.js
  end
end

#updateObject



58
59
60
61
62
63
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 58

def update
  @post.update!(post_params)
  respond_to do |format|
    format.js
  end
end