Class: Formily::FormsController
- Inherits:
-
FormilyController
- Object
- ActionController::Base
- FormilyController
- Formily::FormsController
- Defined in:
- app/controllers/formily/forms_controller.rb
Instance Method Summary collapse
- #add_new_response ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #preview ⇒ Object
- #reload_formily_table ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#add_new_response ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/formily/forms_controller.rb', line 93 def add_new_response submit = Formily::Submit.where(params.permit(:form_id, :resource_id, :user_id, :resource_type)) .order(created_at: :desc).first if submit.blank? || submit.state == 0 || submit.input_values.count == 0 render json: {msg: 'Complete the outstanding form instead of adding a new copy'}, status: :unprocessable_entity else submit = Formily::Submit.new(params.permit(:form_id, :resource_id, :user_id, :resource_type)) submit.save render json: {}, status: :ok end end |
#create ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/formily/forms_controller.rb', line 29 def create form = Formily::Form.new(form_params) if form.save if params[:inputs] params[:inputs].each do |input| i = form.inputs.build(input.to_hash.except('group_inputs')) i.save if input[:group_inputs] input[:group_inputs].each do |gi| t = i.inputs.build(gi.to_hash) t.save end end end end redirect_to formily_forms_path(@params_hash) else redirect_to formily_forms_path(@params_hash) end end |
#destroy ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/formily/forms_controller.rb', line 66 def destroy form = Formily::Form.find(params[:id]) count = Formily::Submit.where(form_id: form.id).count if count > 0 form.update(is_deleted: true) else form.destroy end redirect_to formily_forms_path(@params_hash) end |
#edit ⇒ Object
25 26 27 |
# File 'app/controllers/formily/forms_controller.rb', line 25 def edit @form = Formily::Form.includes(:inputs).find(params[:id]) end |
#index ⇒ Object
6 7 8 9 10 11 12 |
# File 'app/controllers/formily/forms_controller.rb', line 6 def index @forms = if params[:all].present? Formily::Form.includes(:form_type).all else Formily::Form.includes(:form_type).where(is_deleted: false) end end |
#new ⇒ Object
14 15 16 |
# File 'app/controllers/formily/forms_controller.rb', line 14 def new @form = Formily::Form.new(id: 0) end |
#preview ⇒ Object
79 80 81 82 83 84 |
# File 'app/controllers/formily/forms_controller.rb', line 79 def preview form = Formily::Form.find_by(id: params[:formily_form][:id]) form ||= Formily::Form.new submit = Formily::Submit.new(created_at: DateTime.now) render partial: 'preview', layout: false, locals: {:@form => form, :@obj_rel => form, :@submit => submit} end |
#reload_formily_table ⇒ Object
86 87 88 89 90 91 |
# File 'app/controllers/formily/forms_controller.rb', line 86 def reload_formily_table user_id = params[:user_id] obj_rel = params[:resource_type].safe_constantize.find(params[:resource_id]) render locals: {obj_rel: obj_rel, user_id: user_id, flag: params[:flag].present?}, layout: false end |