Class: Formily::FormilyableController
- Inherits:
-
FormilyController
- Object
- ActionController::Base
- FormilyController
- Formily::FormilyableController
- Defined in:
- app/controllers/formily/formilyable_controller.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #select_data ⇒ Object
Instance Method Details
#connect ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/formily/formilyable_controller.rb', line 67 def connect @page_name = 'Formily forms | Connect' @forms = Formily::Form.all @not_manage = true @model = @model_name.safe_constantize.find(@model_id) @select_forms = Formily::Form.where.not(id: @model.formily_forms.pluck(:id)) end |
#create ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/formily/formilyable_controller.rb', line 34 def create formilyable = Formily::FormilyableForm.new(formilyable_params) url = params[:iframe].present? ? new_formily_formilyable_path(iframe: true) : formily_forms_assign_path if formilyable.save redirect_to url else redirect_to url end end |
#destroy ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'app/controllers/formily/formilyable_controller.rb', line 46 def destroy formilyable = Formily::FormilyableForm.find(params[:id]) formilyable.destroy url = params[:iframe].present? ? new_formily_formilyable_path(iframe: true) : formily_forms_assign_path redirect_to url end |
#index ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/controllers/formily/formilyable_controller.rb', line 4 def index @forms = Formily::Form.all @select_forms = Formily::Form.select(:id, :title) @related_forms = Formily::FormilyableForm.order(created_at: :desc) @related_forms = if params[:all].present? Formily::FormilyableForm.order(created_at: :desc) else Formily::FormilyableForm.joins(:form).order(created_at: :desc).where(formily_forms: {is_deleted: false}) end end |
#new ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/formily/formilyable_controller.rb', line 16 def new # Set user data if params[:model_name].present? session[:model] = { 'model_name' => params[:model_name], 'model_id' => params[:model_id], 'user_id' => params[:user_id] } end @related_model = session[:model] @forms = Formily::FormilyableForm.includes(:form). where(formilyable_type: @related_model['model_name'], formilyable_id: @related_model['model_id']) @model = get_model @select_forms = Formily::Form.where.not(id: @model.formily_forms.pluck(:id)) end |
#select_data ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/formily/formilyable_controller.rb', line 55 def select_data model = params[:formilyable_type].safe_constantize ids = Formily::FormilyableForm.where(formilyable_type: params[:formilyable_type], form_id: params[:form_id]).pluck(:formilyable_id) data = model.where.not(id: ids) render json: data.to_json(only: [:id], methods: :formily_title) end |