Class: Cms9::PostDefinitionsController
Instance Method Summary
collapse
#authorize, #current_user, #user_logout
Instance Method Details
#create ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/controllers/cms9/post_definitions_controller.rb', line 15
def create
@post = PostDefinition.new(post_definition_params)
@post.user_id = current_user.id
if PostDefinition.where(name: @post[:name]).blank?
if @post.save
@field = PostField.new({
'name': 'Title',
'field_type': 'text',
'required': true,
'post_definition_id': @post.id,
'user_id': current_user.id
})
if @field.save
Cms9Events.new.create_event('post_definition', @post.id, params[:action], current_user, nil)
redirect_to edit_post_definition_path(@post.id)
end
else
render :new
end
else
@post.errors.add(:name, " Post Type already exist")
render :new
end
end
|
#destroy ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
|
# File 'app/controllers/cms9/post_definitions_controller.rb', line 68
def destroy
@post_def = PostDefinition.find(params[:id])
@post_def.destroy
Cms9Events.new.create_event('post_definition', @post_def.id, params[:action], current_user, @post_def.name)
@posts = Post.where(post_definition_id: params[:id])
@posts.destroy_all
redirect_to post_definitions_path
end
|
#edit ⇒ Object
11
12
13
|
# File 'app/controllers/cms9/post_definitions_controller.rb', line 11
def edit
@post = PostDefinition.find(params[:id])
end
|
#index ⇒ Object
3
4
5
|
# File 'app/controllers/cms9/post_definitions_controller.rb', line 3
def index
@posts = PostDefinition.order('created_at desc').page(params[:page]).per(20)
end
|
#new ⇒ Object
7
8
9
|
# File 'app/controllers/cms9/post_definitions_controller.rb', line 7
def new
@post = PostDefinition.new
end
|
#update ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'app/controllers/cms9/post_definitions_controller.rb', line 46
def update
@post = PostDefinition.find(params[:id])
@post.user_id = current_user.id
field = PostDefinition.where(name: params[:post_definition][:name].downcase)
if field.blank? || @post.name == params[:post_definition][:name]
if @post.update(post_definition_params)
Cms9Events.new.create_event('post_definition', @post.id, params[:action], current_user, nil)
redirect_to edit_post_definition_path(@post.id)
else
render :edit
end
else
@post.errors.add(:name, " Post Type already exist")
render :edit
end
end
|