Rails, two-dimensional table, summary, nested hash loops

I am creating a class report — a two-dimensional table that shows the names of the lessons going horizontally and the list of students going vertically.

Student Name | LessonID x | LessonID x | LessonID x Joe 95% 95% Mary 80% 80% Sam 80% 80% 

My data is in a table with these fields:

 student_id, lesson_id, grade_in_pct, grade_in_pts, grade_high, grade_low, grade_median 

The total number of students and lessons is not fixed.

I considered using the ruport / actions_as_reportable procedure or mysql pivot procedure, however it seems that the axis collapses only one dimension. In order not to work, because, in my opinion, I want to add mouse functions and conditional formatting to show more information about each class.

So, I think my only option is to create a nested hash and then scroll it in the view. What do you think? Can anyone suggest a way to create a nested hash? Would it be too processor intensive to go through 250 lines (~ 50 students, 5 lessons each)?

I am stuck. Please help. Thanks!

+6
arrays ruby-on-rails hash pivot
source share
1 answer

Here's how I do it:

 MODELS: Student Model: has_many: Grades has_and_belongs_to_many: Lessons Lesson Model: has_many: Grades has_and_belongs_to_many: Students Grade Model: belongs_to: Student, Lesson CONTROLLER: @data = Student.all @lessons = Lesson.all VIEW: header_row @data.each do |student| @lessons.each do |lesson| student.grades.find_by_lesson(lesson).some_data 
+3
source share

All Articles