我的应用程序有不同的用户类型/型号,例如:医生和医疗机构(不确定这些是好名字顺便说一下)。它们与用户具有多态关联。
目前为止的控制器:
HomesController - 验证用户是否已登录。如果是,则重定向到dashboard_path,如果没有重定向到登录页面。
DashboardsController - “显示当前用户个人资料”。代码:
class DashboardsController < ApplicationController
before_filter :authenticate_user!
def show
@user = current_user.profile
render "#{@user.dashboard_something_variable}_dashboard"
end
end
这是一个好主意,还是你会拆分控制器?我觉得DoctorsController的展示动作将是让其他人查看放射科医生的个人资料,而不是让博士自己查看他的个人资料/私事。
谢谢!
答案 0 :(得分:1)
您可以为每个视图设置一个部分..
def show
# ...
@partial = current_user.profile # 'doctor', 'radiologist',...
end
在show.html.erb中:
<%= render @partial %>
然后,您可以将每个视图保存在控制器的视图文件夹中,例如_doctor.html.erb
,_radiologist.html.erb
。