我的應用程序有兩個用戶,doctors
和hospitals
。醫生可以查看病例並對其進行診斷,醫院可以爲醫生創建病例以供診斷。這些都是從他們自己的用戶配置文件完成的。如何將不同的控制器映射到Rails中的1條路徑?
路線設置的方式是這樣的:doctor_profile_path:轉到醫生的檔案。 hospital_profile_path:去醫院的個人資料。
我想profile_path
重定向到用戶的個人資料,無論他們擁有哪個帳戶。這樣他們在醫院時也不能去doctor_profile_path
,路徑名稱更簡潔。我該怎麼做呢?
其他問題:
- 如何實現授權?
- 視圖文件夾應該如何構建?
routes.rb。我試圖把路徑: '個人資料',但Rails會剛剛找到第一個可用的匹配,因此不能正常工作
resource :doctor_profile, only: :do do
resources :plates, controller: 'doctor/cases', only: [:index, :show] do
post '/claim', action: 'claim'
end
end
resource :hospital_profile, only: :do do
resources :cases, controller: 'hospital/cases', only: [:new, :create]
end
控制器結構是這樣的:
doctor/
-> cases_controller #=> contains the actions a doctor can do with a case
-> (things the doctor can do on his profile)
hospital
-> cases_controller #=> contains the actions a hospital can do with a case
-> (things a hospital can do on his profile)
profile_controller.rb
(這是How to create routes for 2 types of users accessing the same resource?的延續)
你在使用設計嗎?如果是這樣,醫生和醫院都使用相同的用戶資源登錄? – rmagnum2002
感謝您回覆@ rmagnum2002。對。這兩種賬戶只需一次認證。我應該使用兩個? –
加入此聊天http://chat.stackoverflow.com/rooms/49149/http-stackoverflow-com-questions-22223608-how-can-i-map-different-controllers-t – rmagnum2002