Class: Cms9::PostFieldsController
Overview
Instance Method Summary
collapse
#authorize, #current_user, #user_logout
Instance Method Details
#create ⇒ Object
10
11
12
13
14
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
|
# File 'app/controllers/cms9/post_fields_controller.rb', line 10
def create
@field = PostField.new(post_field_params)
@field.user_id = current_user.id
if PostField.where(name: @field[:name],
post_definition_id: @field[:post_definition_id]).blank?
if %w(select_single select_multiple).include?(@field[:field_type])
@field.metadata = ''
values = params[:multi_values]
values.each_with_index do |value, index|
if value != '' && index.zero?
@field.metadata = value
elsif !index.zero?
@field.metadata = @field.metadata + ',' + value
end
end
elsif !%w(select_single select_multiple image)
.include?(@field[:field_type])
@field.metadata = nil
end
if @field.save
create_post_field_event
redirect_to edit_post_definition_path(id: @field.post_definition_id)
else
render :new
end
else
@field.errors.add(:name, 'of field already exist')
render :new
end
end
|
#destroy ⇒ Object
73
74
75
76
77
78
|
# File 'app/controllers/cms9/post_fields_controller.rb', line 73
def destroy
@field = PostField.find(params[:id])
@field.destroy
create_post_field_event
redirect_to request.referrer
end
|
#edit ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'app/controllers/cms9/post_fields_controller.rb', line 44
def edit
@field = PostField.find(params[:id])
@post_name = params[:post]
@field.field_type = params[:type] unless PostField.all_types
.index(params[:type])
.nil?
@field.name = params[:field_name] unless params[:field_name].nil?
end
|
#new ⇒ Object
4
5
6
7
|
# File 'app/controllers/cms9/post_fields_controller.rb', line 4
def new
@field = PostField.new
@field.post_definition_id = params[:post_definition_id]
end
|
#update ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/controllers/cms9/post_fields_controller.rb', line 53
def update
@field = PostField.find(params[:id])
@field.user_id = current_user.id
field = PostField.where(name: post_field_params[:name],
post_definition_id: @field[:post_definition_id])
if field.blank? || field.pluck(:id)[0].to_s == params[:id]
check_selectors
if @field.update(post_field_params)
create_post_field_event
redirect_to edit_post_definition_path(id: @field.post_definition_id)
else
render :edit
end
else
@field.errors.add(:name, 'of field already exist')
render :edit
end
end
|