Class: Cms9::PostFieldsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/cms9/post_fields_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authorize, #current_user, #user_logout

Instance Method Details

#createObject



8
9
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
# File 'app/controllers/cms9/post_fields_controller.rb', line 8

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 @field[:field_type] == 'select_single' || @field[:field_type] == 'select_multiple'
      @field. = ''
      values = params[:multi_values]

      values.each_with_index do |value, index|
        if value != ''
          if index == 0
            @field. = value
          elsif
            @field. = @field. + ',' + value
          end
        end
      end
    elsif @field[:field_type] != 'select_single' && @field[:field_type] != 'select_multiple' && @field[:field_type] != 'image'
      @field. = nil
    end

    if @field.save
      Cms9Events.new.create_event('post_definition', @field[:post_definition_id], 'update', current_user, nil)
      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

#destroyObject



94
95
96
97
98
99
100
101
# File 'app/controllers/cms9/post_fields_controller.rb', line 94

def destroy
  @field = PostField.find(params[:id])
  @field.destroy

  Cms9Events.new.create_event('post_definition', @field[:post_definition_id], 'update', current_user, nil)

  redirect_to request.referrer
end

#editObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/cms9/post_fields_controller.rb', line 42

def edit
  @field = PostField.find(params[:id])
  @post_name = params[:post]

  if PostField.all_types.index(params[:type]) != nil
    @field.field_type = params[:type]
  end

  if params[:field_name] != nil
    @field.name = params[:field_name]
  end
end

#newObject



3
4
5
6
# File 'app/controllers/cms9/post_fields_controller.rb', line 3

def new
  @field = PostField.new
  @field.post_definition_id = params[:post_definition_id]
end

#updateObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/cms9/post_fields_controller.rb', line 55

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]
    if @field[:field_type] == 'select_single' || @field[:field_type] == 'select_multiple'
      @field. = ''
      values = params[:multi_values]

      values.each_with_index do |value, index|
        if value != ''
          if index == 0
            @field. = value
          elsif
            @field. = @field. + ',' + value
          end
        end
      end

      params[:post_field][:metadata] = @field.

    elsif @field[:field_type] != 'select_single' && @field[:field_type] != 'select_multiple' && @field[:field_type] != 'image'
      @field. = nil
    end

    if @field.update(post_field_params)
      Cms9Events.new.create_event('post_definition', @field[:post_definition_id], 'update', current_user, nil)
      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