Class: Admin::FormTemplatesController

Inherits:
StaffController
  • Object
show all
Defined in:
app/controllers/admin/form_templates_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/admin/form_templates_controller.rb', line 33

def create
  params.require(:name)
  params.require(:template)

  begin
    template = FormTemplate.create!(name: params[:name], template: params[:template])
    render_serialized(template, AdminFormTemplateSerializer, root: "form_template")
  rescue FormTemplate::NotAllowed => err
    render_json_error(err.message)
  end
end

#destroyObject



65
66
67
68
69
70
# File 'app/controllers/admin/form_templates_controller.rb', line 65

def destroy
  template = FormTemplate.find(params[:id])
  template.destroy!

  render json: success_json
end

#editObject



50
51
52
# File 'app/controllers/admin/form_templates_controller.rb', line 50

def edit
  FormTemplate.find(params[:id])
end

#indexObject



6
7
8
9
# File 'app/controllers/admin/form_templates_controller.rb', line 6

def index
  form_templates = FormTemplate.all.order(:id)
  render_serialized(form_templates, AdminFormTemplateSerializer, root: "form_templates")
end

#newObject



11
12
# File 'app/controllers/admin/form_templates_controller.rb', line 11

def new
end

#previewObject



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

def preview
  params.require(:name)
  params.require(:template)

  if params[:id].present?
    template = FormTemplate.find(params[:id])
    template.assign_attributes(name: params[:name], template: params[:template])
  else
    template = FormTemplate.new(name: params[:name], template: params[:template])
  end

  begin
    template.validate!
    render json: success_json
  rescue FormTemplate::NotAllowed => err
    render_json_error(err.message)
  end
end

#showObject



45
46
47
48
# File 'app/controllers/admin/form_templates_controller.rb', line 45

def show
  template = FormTemplate.find(params[:id])
  render_serialized(template, AdminFormTemplateSerializer, root: "form_template")
end

#updateObject



54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/admin/form_templates_controller.rb', line 54

def update
  template = FormTemplate.find(params[:id])

  begin
    template.update!(name: params[:name], template: params[:template])
    render_serialized(template, AdminFormTemplateSerializer, root: "form_template")
  rescue FormTemplate::NotAllowed => err
    render_json_error(err.message)
  end
end