My app has different user types/model, ex: Doctor and MedicalInstitution (not sure if those are good names btw). They have polymorphic association to User.
The controllers so far:
HomesController - Verify if user is logged in or not. If yes redirect to dashboard_path if not redirect to landing page.
DashboardsController - "Display the current user profile." Code:
class DashboardsController < ApplicationController
before_filter :authenticate_user!
def show
@user = current_user.profile
render "#{@user.dashboard_something_variable}_dashboard"
end
end
Is this a good idea, or would you split the controllers? I feel that DoctorsController's show action would be for other people to view radiologist profiles, not for the Doctor himself to view his profile/private things.
Thank you!
You could set up a partial for each view..
def show
# ...
@partial = current_user.profile # 'doctor', 'radiologist',...
end
In show.html.erb:
<%= render @partial %>
Then you would save each view partial in the controller's views folder, eg _doctor.html.erb
, _radiologist.html.erb
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.