fix new error

This commit is contained in:
chiu 2019-12-30 13:11:46 +08:00
parent 28b824f018
commit 57167f9d08
2 changed files with 35 additions and 14 deletions

View File

@ -31,7 +31,7 @@ class Admin::SeminarsController < OrbitAdminController
sort = {params[:sort].to_sym=>params[:order]} sort = {params[:sort].to_sym=>params[:order]}
end end
else else
sort = {:signup_start_date=>"desc"} sort = {:signup_start_date=>"desc"}
end end
@seminars = SeminarMain.all.order_by(sort).with_categories(filters("category")) @seminars = SeminarMain.all.order_by(sort).with_categories(filters("category"))
@ -60,7 +60,7 @@ class Admin::SeminarsController < OrbitAdminController
def new def new
@member = nil @member = nil
@seminar = SeminarMain.new @seminar = SeminarMain.new
create_set create_set (false)
@signup_sets = @seminar.seminar_signup_field_sets @signup_sets = @seminar.seminar_signup_field_sets
@submission_set = @seminar.seminar_submission_field_sets @submission_set = @seminar.seminar_submission_field_sets
@custom_set = @seminar.seminar_signup_field_customs @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? seminar_params['seminar_links_attributes'].delete(idx.to_s) if link['url'].blank?
end end
end end
seminar_main_params = seminar_params
seminar = SeminarMain.new(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.create_user_id = current_user.id
seminar.update_user_id = current_user.id seminar.update_user_id = current_user.id
seminar.save 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'] redirect_to params['referer_url']
end end
@ -105,7 +112,7 @@ class Admin::SeminarsController < OrbitAdminController
custom_set.delete custom_set.delete
end end
end end
create_set create_set (true)
@signup_sets = @seminar.seminar_signup_field_sets @signup_sets = @seminar.seminar_signup_field_sets
@submission_set = @seminar.seminar_submission_field_sets @submission_set = @seminar.seminar_submission_field_sets
@custom_set = @seminar.seminar_signup_field_customs @custom_set = @seminar.seminar_signup_field_customs
@ -231,7 +238,7 @@ class Admin::SeminarsController < OrbitAdminController
def seminar_params def seminar_params
params.require(:seminar_main).permit! params.require(:seminar_main).permit!
end end
def create_set def create_set (save_flag)
SeminarSignup.attribute_names.each do |attr_signup| SeminarSignup.attribute_names.each do |attr_signup|
if !(['_id', 'created_at', 'updated_at','seminar_main_id'].include? 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 } 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}") name1[locale] = t("seminar_signup.#{attr_signup}")
end end
I18n.locale = now_locale 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 end
end end
@ -265,8 +276,12 @@ class Admin::SeminarsController < OrbitAdminController
I18n.locale = locale I18n.locale = locale
name1[locale] = t("seminar_signup.recaptcha") name1[locale] = t("seminar_signup.recaptcha")
end end
I18n.locale = now_locale I18n.locale = now_locale
@seminar.seminar_signup_field_sets.create(field_name:'recaptcha',name:name1,placeholder:name1,hidden:true) 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 end
SeminarSignupContribute.attribute_names.each do |attr_submission| SeminarSignupContribute.attribute_names.each do |attr_submission|
if !(['_id', 'created_at', 'updated_at','seminar_signup_id'].include? 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 I18n.locale = locale
name1[locale] = t("seminar_signup.#{attr_submission}") name1[locale] = t("seminar_signup.#{attr_submission}")
end end
I18n.locale = now_locale I18n.locale = now_locale
@seminar.seminar_submission_field_sets.create(field_name:attr_submission,name:name1,placeholder:name1) 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 end
end end

View File

@ -168,6 +168,7 @@
<%= show_set_field(attr_signup,'seminar_signup_field_sets',signup_index,'placeholder') %> <%= show_set_field(attr_signup,'seminar_signup_field_sets',signup_index,'placeholder') %>
</td> </td>
<td> <td>
<input type="hidden" class="field_name" name='<%= "seminar_main[seminar_signup_field_sets][#{signup_index}][field_name]" %>' value="<%= attr_signup.field_name %>">
<input type="hidden" class="field_set" name='<%= "seminar_main[seminar_signup_field_sets][#{signup_index}][disabled]" %>' value="false"> <input type="hidden" class="field_set" name='<%= "seminar_main[seminar_signup_field_sets][#{signup_index}][disabled]" %>' value="false">
<%= check_box_tag("seminar_main[seminar_signup_field_sets][#{signup_index}][disabled]", true ,attr_signup.disabled) %> <%= check_box_tag("seminar_main[seminar_signup_field_sets][#{signup_index}][disabled]", true ,attr_signup.disabled) %>
</td> </td>
@ -206,6 +207,7 @@
<%= show_set_field(attr_signup,'seminar_submission_field_sets',submission_index,'placeholder') %> <%= show_set_field(attr_signup,'seminar_submission_field_sets',submission_index,'placeholder') %>
</td> </td>
<td> <td>
<input type="hidden" class="field_name" name='<%= "seminar_main[seminar_submission_field_sets][#{submission_index}][field_name]" %>' value="<%= attr_signup.field_name %>">
<input type="hidden" class="field_set" name='<%= "seminar_main[seminar_submission_field_sets][#{submission_index}][disabled]" %>' value="false"> <input type="hidden" class="field_set" name='<%= "seminar_main[seminar_submission_field_sets][#{submission_index}][disabled]" %>' value="false">
<%= check_box_tag("seminar_main[seminar_submission_field_sets][#{submission_index}][disabled]", true ,attr_signup.disabled) %> <%= check_box_tag("seminar_main[seminar_submission_field_sets][#{submission_index}][disabled]", true ,attr_signup.disabled) %>
</td> </td>