Class: PostsController
Instance Attribute Summary
#req, #res
Instance Method Summary
collapse
#boolean_param, #csrf_token, #delete_all_images_from_content, #delete_from_storage, #initialize, #params, #redirect_to, #render, #session, #validate!
Instance Method Details
#create ⇒ Object
14
15
16
17
18
19
20
21
22
23
|
# File 'app/controllers/posts_controller.rb', line 14
def create
data = params['post']
data['is_active'] = boolean_param(data['is_active'])
@post = Post.new(data)
if @post.save
redirect_to '/dashboard/posts'
else
render 'cms/posts_form'
end
end
|
#destroy ⇒ Object
41
42
43
44
45
46
47
|
# File 'app/controllers/posts_controller.rb', line 41
def destroy
@post = Post[params['id']]
delete_from_storage(@post.image_url) if @post.respond_to?(:image_url)
delete_all_images_from_content(@post.content) if @post.respond_to?(:content)
@post.destroy
redirect_to '/dashboard/posts'
end
|
#edit ⇒ Object
25
26
27
28
|
# File 'app/controllers/posts_controller.rb', line 25
def edit
@post = Post[params['id']]
render 'cms/posts_form'
end
|
#index ⇒ Object
4
5
6
7
|
# File 'app/controllers/posts_controller.rb', line 4
def index
@posts = Post.order(Sequel.desc(:created_at)).all
render 'cms/posts_index'
end
|
#new ⇒ Object
9
10
11
12
|
# File 'app/controllers/posts_controller.rb', line 9
def new
@post = Post.new
render 'cms/posts_form'
end
|
#update ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'app/controllers/posts_controller.rb', line 30
def update
@post = Post[params['id']]
data = params['post']
data['is_active'] = boolean_param(data['is_active'])
if @post.update(data)
redirect_to '/dashboard/posts'
else
render 'cms/posts_form'
end
end
|