我有一个名为 的模型Student
,其中有一个名为的属性University_ID
。
我创建了一个自定义操作和路由,通过以下链接显示特定学生的详细信息:students/2/details
即students/:id/details
但是,我希望能够允许用户使用他们的大学 ID 而不是数据库 ID,以便以下内容可以工作,students/X1234521/details
例如students/:university_id/details
我的路由文件现在看起来像这样:
resources :students
match 'students/:id/details' => 'students#details', :as => 'details'
但是,这使用 Student_ID 而不是 University_ID,我已经尝试过
match 'students/:university_id/details' => 'students#details', :as => 'details'
,但这仅对应于 Student_ID,而不对应于 University_ID。
我的控制器看起来像这样,如果这有任何帮助:
def details
@student = Student.find(params[:id])
end
我也尝试过,@student = Student.find(params[:university_id])
但没有,没有任何效果。