← Back to Upcase

How would you handle different profile pages based on a user type?

(Daryll Santos) #1

I’m relatively new! I based my controller structure on the learn project.

My app has different user types/model. Radiologist and MedicalInstitution (not sure if those are good names btw). They have polymorphic association to User.

I would like each of the

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.
Dashboard Controller - “Display the current user profile.” Code:

class DashboardsController < ApplicationController
  before_filter :authenticate_user!
  def show
    @user = current_user.profile
    render # ????:(based on @user.role or something)

Is this a good idea, or would you split the controllers? I feel that RadiologistController’s show action would be for other people to view radiologist profiles, not for the Radiologist himself to view his profile/private things.

Thank you!

(Guirec Corbel) #2

If your view is totaly different I think your should use render @user.role but if you have some similar parts, you should use a partial and use the same method in the view.

I think it’s the more simpler and obvious way if controller are similar. You will duplicate your code if you create other controllers.

(Daryll Santos) #3

Thank you @guirec. I guess it depends on how much is duplicated. Going up a level, is this how you would represent “different profile pages for different types of users”? I think the closest analogy to this is in E-commerce. Sellers have their own profile pages, and buyers have their own profile pages.

BTW the associated SO question is here: http://stackoverflow.com/questions/22072142/rails-rendering-different-dashboard-user-profile-depending-on-the-type-of-us