Class: Cms9::PostDefinitionsController
Overview
post definition controller
Instance Method Summary
collapse
#authorize, #current_user, #user_logout
Instance Method Details
#create ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'app/controllers/cms9/post_definitions_controller.rb', line 19
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
create_post_event
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
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'app/controllers/cms9/post_definitions_controller.rb', line 61
def destroy
@post_def = PostDefinition.find(params[:id])
@posts = Post.where(post_definition_id: params[:id])
@posts.each do |post|
Cms9Events.new.create_event('post', post[:id], params[:action],
current_user, post_name(post))
end
@posts.destroy_all
@post_def.destroy
create_post_def_event(@post_def.name)
redirect_to post_definitions_path
end
|
#edit ⇒ Object
14
15
16
|
# File 'app/controllers/cms9/post_definitions_controller.rb', line 14
def edit
@post = PostDefinition.find(params[:id])
end
|
#index ⇒ Object
4
5
6
7
8
|
# File 'app/controllers/cms9/post_definitions_controller.rb', line 4
def index
@posts = PostDefinition.order('created_at desc')
.page(params[:page])
.per(20)
end
|
#new ⇒ Object
10
11
12
|
# File 'app/controllers/cms9/post_definitions_controller.rb', line 10
def new
@post = PostDefinition.new
end
|
#update ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'app/controllers/cms9/post_definitions_controller.rb', line 41
def update
@post = PostDefinition.find(params[:id])
@post.user_id = current_user.id
post_definition_name = params[:post_definition][:name]
field = PostDefinition.where(name: post_definition_name.downcase)
if field.blank? || @post.name == post_definition_name
if @post.update(post_definition_params)
create_post_event
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
|