Class: Cms9::PostsController
Instance Method Summary
collapse
#authorize, #current_user, #user_logout
Instance Method Details
#create ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/controllers/cms9/posts_controller.rb', line 20
def create
@post = Post.new(post_params)
@post.user_id = current_user.id
if @post.save
Cms9Events.new.create_event('post', @post.id, params[:action], current_user, nil)
redirect_to posts_path(post_definition_id: @post.post_definition.id)
else
render :new
end
end
|
#destroy ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'app/controllers/cms9/posts_controller.rb', line 56
def destroy
@post = Post.find(params[:id])
post_definition_id = @post.post_definition.id
post_name = Field.where(post_field_id: @post.post_definition.post_fields[0].id, post_id: @post.id)[0]
Cms9Events.new.create_event('post', @post.id, params[:action], current_user, post_name)
@post.destroy
redirect_to posts_path(post_definition_id: post_definition_id)
end
|
#edit ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'app/controllers/cms9/posts_controller.rb', line 33
def edit
@post = Post.find(params[:id])
@post.post_definition.post_fields.each do |post_field|
if @post.fields.where(post_field_id: post_field[:id]).blank?
@post.fields.build(post_field: post_field)
end
end
end
|
#index ⇒ Object
3
4
5
6
7
8
9
|
# File 'app/controllers/cms9/posts_controller.rb', line 3
def index
@post_definition = Cms9::PostDefinition.find(params[:post_definition_id])
@posts = Post.where(post_definition: @post_definition)
.order('created_at desc')
.page(params[:page])
.per(20)
end
|
#new ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'app/controllers/cms9/posts_controller.rb', line 11
def new
@post = Post.new
@post.post_definition_id = params[:post_definition_id]
@post.post_definition.post_fields.each do |post_field|
@post.fields.build(post_field: post_field)
end
end
|
#update ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'app/controllers/cms9/posts_controller.rb', line 43
def update
@post = Post.find(params[:id])
@post.user_id = current_user.id
if @post.update(post_params)
Cms9Events.new.create_event('post', @post.id, params[:action], current_user, nil)
redirect_to posts_path(post_definition_id: @post.post_definition.id)
else
render :edit
end
end
|