diff --git a/app/controllers/olympiamanagements_controller.rb b/app/controllers/olympiamanagements_controller.rb index 8723af7..809afad 100644 --- a/app/controllers/olympiamanagements_controller.rb +++ b/app/controllers/olympiamanagements_controller.rb @@ -196,7 +196,7 @@ class OlympiamanagementsController < ApplicationController render_contents_in_index_page(@breadcumb+"

#{I18n.t('olympiamanagement.please_set_school_connect_data')}

".html_safe) else @student_data_field = StudentDataField.first - @olympia_student_data = OlympiaStudentDataFields.new + @olympia_student_data = (OlympiaStudentDataFields.find(params[:id]) rescue OlympiaStudentDataFields.new) @page_content = render_to_string(:formats=> [:html] ,:partial=>'add_student_data.html',:locals=>{:@error=>(@@error rescue nil),:@student_data_field=>@student_data_field,:@olympia_student_data=>@olympia_student_data}) render_contents_in_index_page(@breadcumb+@page_content.html_safe) end @@ -529,8 +529,9 @@ class OlympiamanagementsController < ApplicationController end def updata_student_data if params[:type] == 'add_student_data' - @olympia_student_data = OlympiaStudentDataFields.create(params.require(:add_student_data).permit(:StudentIdentity,:StudentName,:StudentSex,:StudentIDNO, - :StudentBirthMonth,:StudentBirthDay,:StudentClass,:StudentPhone,:StudentCode,:StudentAddress,:StudentArea,:StudentFile)) + @student_params = params.require(:add_student_data).permit(:StudentIdentity,:StudentName,:StudentSex,:StudentIDNO,:StudentBirthMonth,:StudentBirthDay,:StudentClass,:StudentPhone,:StudentCode,:StudentAddress,:StudentArea,:StudentFile) + @olympia_student_data = OlympiaStudentDataFields.find(params[:id]) rescue nil + @olympia_student_data.nil? ? OlympiaStudentDataFields.create(@student_params) : @olympia_student_data.update_attributes(@student_params) redirect_to sign_up_student_data_list_olympiamanagements_path else render :html => '404' diff --git a/app/views/olympiamanagements/_add_student_data.html.erb b/app/views/olympiamanagements/_add_student_data.html.erb index 0a9f3d6..a1bd406 100644 --- a/app/views/olympiamanagements/_add_student_data.html.erb +++ b/app/views/olympiamanagements/_add_student_data.html.erb @@ -15,7 +15,7 @@ <%end%>
  • <% if field.values[0][:type] == 'String' %> - " value="<%= (field.keys[0]=="enrollment_limited"&&(@olympia_student_data[field.keys[0]].nil? || @olympia_school_data_field[field.keys[0]] == 0) ) ? "" : @olympia_school_data_field[field.keys[0]] %>" size="<%=field.values[0][:size]%>" id="<%= field.keys[0] %>" class="col_input<%= @extra_class%>"/> + " value="<%= @olympia_student_data[field.keys[0]].to_s %>" size="<%=field.values[0][:size]%>" id="<%= field.keys[0] %>" class="col_input<%= @extra_class%>"/> <% elsif field.values[0][:type] == 'select_num' %> <% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %> <% elsif field.values[0][:type] == 'radio' %> <%field.values[0][:choices].each_with_index do |choice,i|%> - " id="<%="#{field.keys[0]}_#{choice}"%>" class="required" value="<%=choice%>" "<%= (@olympia_student_data[field.keys[0]]== choice) ? 'checked' : '' %>"> + " id="<%="#{field.keys[0]}_#{choice}"%>" class="required" value="<%=choice%>" <%= (@olympia_student_data[field.keys[0]].to_s== choice.to_s) ? 'checked=checked' : '' %>> <% end %> <% elsif field.values[0][:type] == 'File' %> - " value="<%= (field.keys[0]=="enrollment_limited"&&(@olympia_student_data[field.keys[0]].nil? || @olympia_school_data_field[field.keys[0]] == 0) ) ? "" : @olympia_school_data_field[field.keys[0]] %>" size="<%=field.values[0][:size]%>" id="<%= field.keys[0] %>" style="margin-top: 1em;" class="col_input<%= @extra_class%>"/> + " value="<%= @olympia_student_data[field.keys[0]] %>" size="<%=field.values[0][:size]%>" id="<%= field.keys[0] %>" style="margin-top: 1em;" class="col_input<%= @extra_class%>"/> <% end %>
  • <% if !field.values[0][:hint][I18n.locale.to_s].blank? %>