Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## data_file.rb >> def self.save
- trial[last] = trial[last].downcase
- ##school_classes_controller.rb
- def grade_save
- ....
- for class_record in @class_records
- class_record.update_attributes( :grade => nil, :grade_heading => nil)
- end #-----after nito-----
- @fake_file = false
- if (File.exist?(file_ods) || File.exist?(file_xls) || File.exist?(file_xlsx))
- if File.exist?(file_ods)
- sample = file_ods
- elsif File.exist?(file_xls)
- sample = file_xls
- elsif File.exist?(file_xlsx)
- sample = file_xlsx
- end
- @byte_info = File.open(sample).read(4).unpack('C*')
- # puts '----------------------'
- # print @byte_info
- @byte_info = @byte_info.to_s
- if (@byte_info != '20820717224' && File.exist?(file_xls)) || (@byte_info != '807534' && ( File.exist?(file_ods) || File.exist?(file_xlsx)))
- @fake_file = true
- end
- end
- ....
- elsif (File.exist?(file_ods) || File.exist?(file_xls) || File.exist?(file_xlsx)) && !@fake_file # if file is in other format
- ....
- end
- def grade
- @post = ''
- grade = ''
- @heading = Array.new
- @list = Array.new
- @school_class = SchoolClass.find(params[:id])
- newfile = @school_class.id.to_s + '.csv'
- @nograde = 1
- file = "#{RAILS_ROOT}/records/grades/"+newfile
- file_xls = "#{RAILS_ROOT}/records/grades/"+ @school_class.id.to_s + '.xls'
- file_xlsx = "#{RAILS_ROOT}/records/grades/"+ @school_class.id.to_s + '.xlsx'
- file_ods = "#{RAILS_ROOT}/records/grades/"+ @school_class.id.to_s + '.ods'
- @fake_file = false
- if (File.exist?(file_ods) || File.exist?(file_xls) || File.exist?(file_xlsx))
- if File.exist?(file_ods)
- sample = file_ods
- elsif File.exist?(file_xls)
- sample = file_xls
- elsif File.exist?(file_xlsx)
- sample = file_xlsx
- end
- @byte_info = File.open(sample).read(4).unpack('C*')
- # puts '----------------------'
- # print @byte_info
- @byte_info = @byte_info.to_s
- if (@byte_info != '20820717224' && File.exist?(file_xls)) || (@byte_info != '807534' && ( File.exist?(file_ods) || File.exist?(file_xlsx)))
- @fake_file = true
- end
- end
- ....
- elsif (File.exist?(file_ods) || File.exist?(file_xls) || File.exist?(file_xlsx)) && !@fake_file
- ....
- elsif @fake_file
- flash[:error] = 'There is an error on the file you uploaded.'
- @nograde = 0
- else
- @nograde = 0
- end
- respond_to do |format|
- format.html
- format.xml { render :xml => @school_classes }
- end
- end
- ##show_more.html.erb
- ...
- <% if @class_record_grade_h[0] != nil%>
- <h5>GRADE</h5>
- <table border=1 width=100% >
- <tr bgcolor='black'>
- <th><font color=white><%='Student Name'%></font></th>
- <% @class_record_grade_h[0].each do |heading| %>
- <th><font color=white><%=h heading %></font></th>
- <%end%>
- </tr>
- <% @class_records.each_with_index do |class_record, index| %>
- <tr align='center'>
- <% if @class_record_grade[index] != nil%>
- <td>
- <%= link_to class_record.student.last_name + ', ' + class_record.student.name, class_record.student %>
- </td>
- <% @class_record_grade[index].each do |body| %>
- <td><%=h body%></td>
- <%end%>
- <%end%>
- </tr>
- <%end%>
- </table>
- <%else%>
- <h5>GRADE</h5>
- <blockquote><%= render :partial => '/main/notavailable' %></blockquote>
- <%end%>
- ...
Add Comment
Please, Sign In to add comment