app/controllers/formily/forms_controller.rb in formily-0.0.5.5.7 vs app/controllers/formily/forms_controller.rb in formily-0.0.5.5.9
- old
+ new
@@ -15,20 +15,13 @@
@form = Formily::Form.new(id: 0)
end
def show
@form = Formily::Form.find(params[:id])
- model = params[:model_name].safe_constantize
- @obj_rel = model.find(params[:model_id])
-
- @submit = @form.submits.find_by(id: params[:submit_id])
-
- if @submit.blank?
- @submit = Formily::Submit.create({form_id: @form.id, resource_id: params[:model_id],
- user_id: params[:user_id], resource_type: params[:model_name]})
- end
-
+ form_model = params[:model_name].safe_constantize
+ @obj_rel = form_model.find(params[:model_id])
+ @submit = @form.find_or_create_submission_by(params)
end
def edit
@form = Formily::Form.includes(:inputs).find(params[:id])
end
@@ -88,17 +81,15 @@
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
-
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
-
def add_new_response
submit = Formily::Submit.where(params.permit(:form_id, :resource_id, :user_id, :resource_type))
.order(created_at: :desc).first