From 57167f9d08847ecec7f5194a342391ce254ec6c4 Mon Sep 17 00:00:00 2001 From: chiu Date: Mon, 30 Dec 2019 13:11:46 +0800 Subject: [PATCH] fix new error --- app/controllers/admin/seminars_controller.rb | 47 ++++++++++++++------ app/views/admin/seminars/_form.html.erb | 2 + 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/app/controllers/admin/seminars_controller.rb b/app/controllers/admin/seminars_controller.rb index 7139650..108c4c4 100644 --- a/app/controllers/admin/seminars_controller.rb +++ b/app/controllers/admin/seminars_controller.rb @@ -31,7 +31,7 @@ class Admin::SeminarsController < OrbitAdminController sort = {params[:sort].to_sym=>params[:order]} end else - sort = {:signup_start_date=>"desc"} + sort = {:signup_start_date=>"desc"} end @seminars = SeminarMain.all.order_by(sort).with_categories(filters("category")) @@ -60,7 +60,7 @@ class Admin::SeminarsController < OrbitAdminController def new @member = nil @seminar = SeminarMain.new - create_set + create_set (false) @signup_sets = @seminar.seminar_signup_field_sets @submission_set = @seminar.seminar_submission_field_sets @custom_set = @seminar.seminar_signup_field_customs @@ -75,14 +75,21 @@ class Admin::SeminarsController < OrbitAdminController seminar_params['seminar_links_attributes'].delete(idx.to_s) if link['url'].blank? end end - - seminar = SeminarMain.new(seminar_params) - + seminar_main_params = seminar_params + seminar_signup_set_params = seminar_main_params['seminar_signup_field_sets'] + seminar_submission_set_params = seminar_main_params['seminar_submission_field_sets'] + seminar_main_params.delete(:seminar_signup_field_sets) + seminar_main_params.delete(:seminar_submission_field_sets) + seminar = SeminarMain.new(seminar_main_params) seminar.create_user_id = current_user.id seminar.update_user_id = current_user.id - seminar.save - + seminar_signup_set_params.each do |key,value| + seminar.seminar_signup_field_sets.create(value) + end + seminar_submission_set_params.each do |key,value| + seminar.seminar_submission_field_sets.create(value) + end redirect_to params['referer_url'] end @@ -105,7 +112,7 @@ class Admin::SeminarsController < OrbitAdminController custom_set.delete end end - create_set + create_set (true) @signup_sets = @seminar.seminar_signup_field_sets @submission_set = @seminar.seminar_submission_field_sets @custom_set = @seminar.seminar_signup_field_customs @@ -231,7 +238,7 @@ class Admin::SeminarsController < OrbitAdminController def seminar_params params.require(:seminar_main).permit! end - def create_set + def create_set (save_flag) SeminarSignup.attribute_names.each do |attr_signup| if !(['_id', 'created_at', 'updated_at','seminar_main_id'].include? attr_signup) signup_set = @seminar.seminar_signup_field_sets.select{|v| v.field_name==attr_signup } @@ -253,7 +260,11 @@ class Admin::SeminarsController < OrbitAdminController name1[locale] = t("seminar_signup.#{attr_signup}") end I18n.locale = now_locale - @seminar.seminar_signup_field_sets.create(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1) + if save_flag + @seminar.seminar_signup_field_sets.create(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1) + else + @seminar.seminar_signup_field_sets.new(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1) + end end end end @@ -265,8 +276,12 @@ class Admin::SeminarsController < OrbitAdminController I18n.locale = locale name1[locale] = t("seminar_signup.recaptcha") end - I18n.locale = now_locale - @seminar.seminar_signup_field_sets.create(field_name:'recaptcha',name:name1,placeholder:name1,hidden:true) + I18n.locale = now_locale + if save_flag + @seminar.seminar_signup_field_sets.create(field_name:'recaptcha',name:name1,placeholder:name1,hidden:true) + else + @seminar.seminar_signup_field_sets.new(field_name:'recaptcha',name:name1,placeholder:name1,hidden:true) + end end SeminarSignupContribute.attribute_names.each do |attr_submission| if !(['_id', 'created_at', 'updated_at','seminar_signup_id'].include? attr_submission) @@ -278,8 +293,12 @@ class Admin::SeminarsController < OrbitAdminController I18n.locale = locale name1[locale] = t("seminar_signup.#{attr_submission}") end - I18n.locale = now_locale - @seminar.seminar_submission_field_sets.create(field_name:attr_submission,name:name1,placeholder:name1) + I18n.locale = now_locale + if save_flag + @seminar.seminar_submission_field_sets.create(field_name:attr_submission,name:name1,placeholder:name1) + else + @seminar.seminar_submission_field_sets.new(field_name:attr_submission,name:name1,placeholder:name1) + end end end end diff --git a/app/views/admin/seminars/_form.html.erb b/app/views/admin/seminars/_form.html.erb index 18882c3..b6513bf 100644 --- a/app/views/admin/seminars/_form.html.erb +++ b/app/views/admin/seminars/_form.html.erb @@ -168,6 +168,7 @@ <%= show_set_field(attr_signup,'seminar_signup_field_sets',signup_index,'placeholder') %> + <%= check_box_tag("seminar_main[seminar_signup_field_sets][#{signup_index}][disabled]", true ,attr_signup.disabled) %> @@ -206,6 +207,7 @@ <%= show_set_field(attr_signup,'seminar_submission_field_sets',submission_index,'placeholder') %> + <%= check_box_tag("seminar_main[seminar_submission_field_sets][#{submission_index}][disabled]", true ,attr_signup.disabled) %>