Class: Formily::InputsController
- Inherits:
-
FormilyController
- Object
- ActionController::Base
- FormilyController
- Formily::InputsController
- Defined in:
- app/controllers/formily/inputs_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #render_input_html ⇒ Object
- #render_related ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
4 5 6 7 |
# File 'app/controllers/formily/inputs_controller.rb', line 4 def create input = Formily::Input.create(input_params) render json: {id: input.id}, status: :ok end |
#destroy ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/formily/inputs_controller.rb', line 15 def destroy input = Formily::Input.find(params[:id]) count = Formily::InputValue.where(input_id: input.id).count if input.inputs.count > 0 count += Formily::InputValue.where(input_id: input.inputs.map(&:id)).count end if input.type == 'Formily::RadioInput' count += Formily::InputValue.where(input_id: input.group_input_id).count end if input.type == 'Formily::OptionInput' count += Formily::InputValue.where(input_id: input.group_input_id).count end if count > 0 input.update(is_deleted: true) else input.destroy end render nothing: true, status: :ok end |
#render_input_html ⇒ Object
41 42 43 44 45 46 47 |
# File 'app/controllers/formily/inputs_controller.rb', line 41 def render_input_html if params[:type].present? @input = params[:type].constantize.new(params.permit(:id, :name, :label, :description, :type, :field_order, :tag_attributes, :default_value)) render layout: false end end |
#render_related ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/controllers/formily/inputs_controller.rb', line 49 def if params[:related_arr] if params[:related_arr].blank? models = Formily.formily_models data = [] models.each do |model| data << {label: model.to_s, value: model.to_s} data << { label: model.to_s + '->' + model..to_s, value: model.to_s + '->' + model..to_s } end render json: data.to_json, status: :ok else model = if params[:related_arr][0] =~ /->/ params[:related_arr][0].sub(/.*?->/, '').safe_constantize else params[:related_arr][0].safe_constantize end if model tmp = model.new params[:related_arr][1..-1].each do |attr| tmp = tmp.send('build_' + attr) rescue nil tmp = tmp.send(attr) rescue nil unless tmp end if tmp && tmp.class.superclass.name =~ /\Aactiverecord/i model = tmp.class data = [] if model.reflect_on_all_associations.any? model.reflect_on_all_associations.each do |ref| data << {label: ref.name, value: ref.name, macro: ref.macro} if ref.macro =~ /belongs_to/i end end data += model.columns_hash.map{|k,v| {label: k, value: k}} render json: data.to_json, status: :ok else render text: '', status: :ok end end end else render text: '', status: :ok end end |