Handle searching for "CS112" like "CS 112"
Summary
When searching for a specific course, the search function expects the course and number to be separated. This can be seen in the regular expression for handling this case in app/controllers/search_controller.rb.
/[[:alpha:]]{2,4} \d{3}/.match(params[:query]) do |m| # search for a pattern like "CS 112"
subj, num = m[0].split(' ') # Split the matched string into its components, ["CS", "112"]
course = Course.find_by(subject: subj.upcase, course_number: num) # find the course
redirect_to(course_url(course)) unless course.nil? # redirect to the course if it exists
end
Either extend this regular expression or add a new regular expression matcher to account for cases like "CS112".
Helpful Links
- Current implementation: search_controller.rb
- Ruby regular expressions guide
- Regular expression editor to test on
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information