Class: Admin::FormTemplatesController
- Inherits:
-
StaffController
- Object
- StaffController
- Admin::FormTemplatesController
- Defined in:
- app/controllers/admin/form_templates_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #preview ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
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.) end end |
#destroy ⇒ Object
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 |
#edit ⇒ Object
50 51 52 |
# File 'app/controllers/admin/form_templates_controller.rb', line 50 def edit FormTemplate.find(params[:id]) end |
#index ⇒ Object
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 |
#new ⇒ Object
11 12 |
# File 'app/controllers/admin/form_templates_controller.rb', line 11 def new end |
#preview ⇒ Object
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.) end end |
#show ⇒ Object
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 |
#update ⇒ Object
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.) end end |