Class: Cms::FormFieldsController
- Inherits:
-
BaseController
- Object
- ApplicationController
- ApplicationController
- BaseController
- Cms::FormFieldsController
- Defined in:
- app/controllers/cms/form_fields_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #insert_at ⇒ Object
- #new ⇒ Object
- #preview ⇒ Object
- #update ⇒ Object
Methods inherited from BaseController
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
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. }, success: false, status: :unprocessable_entity end end |
#destroy ⇒ Object
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 |
#edit ⇒ Object
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_at ⇒ Object
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 |
#new ⇒ Object
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 |
#preview ⇒ Object
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 |
#update ⇒ Object
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 |