Class: Cms::FormFieldsController

Inherits:
BaseController show all
Defined in:
app/controllers/cms/form_fields_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

allow_guests_to

Methods inherited from ApplicationController

#no_browser_caching

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/cms/form_fields_controller.rb', line 15

def create
  form = Cms::Form.find(params[:form_field].delete(:form_id))
  field = FormField.new(form_field_params)
  field.form = form
  if field.save
    include_edit_path_in_json(field)
    include_delete_path_in_json(field)
    render json: field
  else
    render json: {
        errors: field.errors.full_messages
    },
           success: false,
           status: :unprocessable_entity
  end
end

#destroyObject



47
48
49
50
51
# File 'app/controllers/cms/form_fields_controller.rb', line 47

def destroy
  field = FormField.find(params[:id])
  field.destroy
  render json: field, success: true
end

#editObject



32
33
34
35
# File 'app/controllers/cms/form_fields_controller.rb', line 32

def edit
  @field = FormField.find(params[:id])
  render :new
end

#insert_atObject



53
54
55
56
57
# File 'app/controllers/cms/form_fields_controller.rb', line 53

def insert_at
  field = FormField.find(params[:id])
  field.insert_at(params[:position])
  render json: field
end

#newObject



6
7
8
# File 'app/controllers/cms/form_fields_controller.rb', line 6

def new
  @field = Cms::FormField.new(label: 'Untitled', field_type: params[:field_type], form_id: params[:form_id])
end

#previewObject



10
11
12
13
# File 'app/controllers/cms/form_fields_controller.rb', line 10

def preview
  @form = Cms::Form.find(params[:id])
  @field = Cms::FormField.new(label: 'Untitled', name: :untitled, field_type: params[:field_type], form: @form)
end

#updateObject



37
38
39
40
41
42
43
44
45
# File 'app/controllers/cms/form_fields_controller.rb', line 37

def update
  field = FormField.find(params[:id])
  if field.update form_field_params
    include_edit_path_in_json(field)
    render json: field
  else
    render text: "Fail", status: 500
  end
end