After chatting with @teenOmar to clarify the requirements, here's the solution we came up with, which allows for the existing students/:id/details
route to accept either an id
or a university_id
(which starts with a w
), and uses a before_filter
to populate @student
for use in various controller actions:
class StudentsController < ApplicationController
before_filter :find_student, only: [:show, :edit, :update, :details]
def show
# @student will already be loaded here
# do whatever
end
# same for edit, update, details
private
def find_student
if params[:id] =~ /^w/
@student = Student.find_by_university_id(params[:id])
else
@student = Student.find(params[:id])
end
end
end