Class: Admin::PostsController
Instance Method Summary
collapse
#posts
#current_user, #signed_in?, #url
Instance Method Details
#create ⇒ Object
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
|
#destroy ⇒ Object
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
|
#drafts ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 22
def drafts
posts = Admin::Post
posts = posts.search search_posts_params
@posts = posts.drafted.order('posts.created_at DESC').includes(:titles)
render 'index'
end
|
#edit ⇒ Object
55
56
|
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 55
def edit
end
|
#index ⇒ Object
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
|
#new ⇒ Object
6
7
8
|
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 6
def new
@post = Admin::Post.new
end
|
#published ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 31
def published
posts = Admin::Post
posts = posts.search search_posts_params
@posts = posts.published.order('posts.published_at DESC').includes(:titles)
render 'index'
end
|
#show ⇒ Object
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
|
#toggle ⇒ Object
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
|
#update ⇒ Object
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
|