CSC/ECE 517 Fall 2020 - E2073. Refactor course controller.rb
Introduction
Expertiza is an open source web application in Ruby on Rails. Its purpose is to allow teachers and students an environment to enhance learning. For teachers, they can use this platform to create, edit, or grade assignments. Students are able to view assignments that teachers have posted, create teams for projects, and review other peers assignments. By having one platform for students and teachers to engage, students are able to stay on top of their tasks and teachers can monitor how well their students are learning the material.
Problem
Background
The course controller has many important functionalities such as creating, modifying, and deleting courses. Our task for this assignment is to refactor some of the code in the course_controller.rb file.
Issues that Need to be Fixed
The following tasks were accomplished in this project:
1)The class should be named courses_controller.rb, to follow the current Rails convention that controllers should be named in the plural.
2)Edit the warning message in the copy function
3)Remove duplicate code in the create and update functions
4)Remove create_course_node function as it does not belong in a controller and move it to course_node.rb
Refactors
Issue 1
Issue: The class should be named courses_controller.rb, to follow the current Rails convention that controllers should be named in the plural.
Solution: By changing the name of the class from course_controller.rb to courses_controller.rb, we needed to go through all the files where Course was called and change it to Courses.
Issue 2
Issue: Edit the warning message in the copy function
Solution: When a student submits a file it should be stored at the path that the teacher specifies. If a teacher specifies a path that already has a filed stored then we need to warn the student that the path is already in use and where they should go if they do not want to overwrite the current file.
Issue 3
Issue: Remove duplicate code in the create and update functions
Solution: In the first and second images below, we have removed the redundant code in the create and update functions. We replaced the redundant code with a function called set_courses_fields which we defined in the third image.
Issue 4
Issue: Remove create_course_node function as it does not belong in a controller and move it to course_node.rb
Solution: For the first image, we have removed the course_node function from the courses_controller.rb file. The second image we are in the models folder for course_node.rb and we have moved course_node from course_controller.rb into this file.
Testing
References
Team Information
Project Mentor:
Sahil Papalkar
Project Members:
Nick Garner
Jonathan Nguyen
Surbhi Jha