Class: Admin::PostsController
Instance Method Summary
collapse
#posts
#current_user, #signed_in?, #url
Instance Method Details
#create ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 29
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
39
40
41
42
43
|
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 39
def destroy
post = Admin::Post.find(params[:id])
post.destroy
redirect_to :root
end
|
#edit ⇒ Object
45
46
|
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 45
def edit
end
|
#index ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 9
def index
posts = Admin::Post
if params.has_key?(:q) && !params[:q].blank?
@titles = Admin::Title.search_by_name(params[:q])
posts = posts.where('id in (?)', @titles.pluck(:post_id).uniq.compact)
end
if params.has_key?(:tid) && !params[:tid].blank?
posts = posts.where('? = ANY(posts.tags)', params[:tid])
end
@posts = posts.order('posts.created_at').includes(:titles)
respond_to do |format|
format.html
format.js
end
end
|
#new ⇒ Object
5
6
7
|
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 5
def new
@post = Admin::Post.new
end
|
#show ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 55
def show
respond_to do |format|
format.html do
render layout: false if request.xhr?
end
end
end
|
#toggle ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 63
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
48
49
50
51
52
53
|
# File 'lib/ecrire/app/controllers/admin/posts_controller.rb', line 48
def update
@post.update!(post_params)
respond_to do |format|
format.js
end
end
|