Guest User

Untitled

a guest
May 27th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. ## data_file.rb >> def self.save
  2.  
  3. trial[last] = trial[last].downcase
  4.  
  5.  
  6. ##school_classes_controller.rb
  7.  
  8. def grade_save
  9.  
  10. ....
  11.  
  12.  
  13. for class_record in @class_records
  14. class_record.update_attributes( :grade => nil, :grade_heading => nil)
  15. end #-----after nito-----
  16.  
  17. @fake_file = false
  18.  
  19. if (File.exist?(file_ods) || File.exist?(file_xls) || File.exist?(file_xlsx))
  20. if File.exist?(file_ods)
  21. sample = file_ods
  22. elsif File.exist?(file_xls)
  23. sample = file_xls
  24. elsif File.exist?(file_xlsx)
  25. sample = file_xlsx
  26. end
  27.  
  28. @byte_info = File.open(sample).read(4).unpack('C*')
  29. # puts '----------------------'
  30. # print @byte_info
  31. @byte_info = @byte_info.to_s
  32.  
  33. if (@byte_info != '20820717224' && File.exist?(file_xls)) || (@byte_info != '807534' && ( File.exist?(file_ods) || File.exist?(file_xlsx)))
  34. @fake_file = true
  35. end
  36.  
  37. end
  38.  
  39.  
  40.  
  41. ....
  42.  
  43.  
  44.  
  45. elsif (File.exist?(file_ods) || File.exist?(file_xls) || File.exist?(file_xlsx)) && !@fake_file # if file is in other format
  46.  
  47.  
  48. ....
  49.  
  50.  
  51.  
  52. end
  53.  
  54.  
  55. def grade
  56.  
  57. @post = ''
  58. grade = ''
  59. @heading = Array.new
  60. @list = Array.new
  61. @school_class = SchoolClass.find(params[:id])
  62. newfile = @school_class.id.to_s + '.csv'
  63. @nograde = 1
  64. file = "#{RAILS_ROOT}/records/grades/"+newfile
  65. file_xls = "#{RAILS_ROOT}/records/grades/"+ @school_class.id.to_s + '.xls'
  66. file_xlsx = "#{RAILS_ROOT}/records/grades/"+ @school_class.id.to_s + '.xlsx'
  67. file_ods = "#{RAILS_ROOT}/records/grades/"+ @school_class.id.to_s + '.ods'
  68.  
  69. @fake_file = false
  70.  
  71. if (File.exist?(file_ods) || File.exist?(file_xls) || File.exist?(file_xlsx))
  72. if File.exist?(file_ods)
  73. sample = file_ods
  74. elsif File.exist?(file_xls)
  75. sample = file_xls
  76. elsif File.exist?(file_xlsx)
  77. sample = file_xlsx
  78. end
  79.  
  80. @byte_info = File.open(sample).read(4).unpack('C*')
  81. # puts '----------------------'
  82. # print @byte_info
  83. @byte_info = @byte_info.to_s
  84.  
  85. if (@byte_info != '20820717224' && File.exist?(file_xls)) || (@byte_info != '807534' && ( File.exist?(file_ods) || File.exist?(file_xlsx)))
  86. @fake_file = true
  87. end
  88.  
  89. end
  90.  
  91.  
  92.  
  93. ....
  94.  
  95.  
  96.  
  97.  
  98. elsif (File.exist?(file_ods) || File.exist?(file_xls) || File.exist?(file_xlsx)) && !@fake_file
  99.  
  100.  
  101. ....
  102.  
  103.  
  104.  
  105. elsif @fake_file
  106. flash[:error] = 'There is an error on the file you uploaded.'
  107. @nograde = 0
  108. else
  109. @nograde = 0
  110. end
  111.  
  112. respond_to do |format|
  113. format.html
  114. format.xml { render :xml => @school_classes }
  115. end
  116.  
  117. end
  118.  
  119.  
  120.  
  121.  
  122. ##show_more.html.erb
  123.  
  124. ...
  125.  
  126. <% if @class_record_grade_h[0] != nil%>
  127. <h5>GRADE</h5>
  128. <table border=1 width=100% >
  129. <tr bgcolor='black'>
  130. <th><font color=white><%='Student Name'%></font></th>
  131. <% @class_record_grade_h[0].each do |heading| %>
  132. <th><font color=white><%=h heading %></font></th>
  133. <%end%>
  134. </tr>
  135. <% @class_records.each_with_index do |class_record, index| %>
  136. <tr align='center'>
  137. <% if @class_record_grade[index] != nil%>
  138. <td>
  139. <%= link_to class_record.student.last_name + ', ' + class_record.student.name, class_record.student %>
  140. </td>
  141. <% @class_record_grade[index].each do |body| %>
  142. <td><%=h body%></td>
  143. <%end%>
  144. <%end%>
  145. </tr>
  146. <%end%>
  147. </table>
  148. <%else%>
  149. <h5>GRADE</h5>
  150. <blockquote><%= render :partial => '/main/notavailable' %></blockquote>
  151. <%end%>
  152.  
  153. ...
Add Comment
Please, Sign In to add comment