Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8144559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:25:20+00:00 2026-06-06T13:25:20+00:00

I have three roles: Instuctor, Student, Admin and each have controllers with a home

  • 0

I have three roles: Instuctor, Student, Admin and each have controllers with a “home” view.

so this works fine,

get "instructor/home", :to => "instructor#home"
get "student/home", :to => "student#home"
get "admin/home", :to => "admin#home"

I want to write a vanity url like below which will route based on the role of the user_id to the correct home page.

get "/:user_id/home", :to => "instructor#home" or "student#home" or "admin#home"

How do I accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:25:21+00:00Added an answer on June 6, 2026 at 1:25 pm

    You can’t do this with routes because the routing system does not have the information required to make this decision. All Rails knows at this point of the request is what the parameters are and does not have access to anything in the database.

    What you need is a controller method that can load whatever data is required, presumably the user record, and redirects accordingly using redirect_to.

    This is a fairly standard thing to do.

    Update:

    To perform all of this within a single controller action you will need to split up your logic according to role. An example is:

    class HomeController < ApplicationController
      def home
        case
        when @user.student?
          student_home
        when @user.admin?
          admin_home
        when @user.instructor
          instructor_home
        else
          # Unknown user type? Render error or use a default.
        end
      end
    
    protected
      def instructor_home
        # ...
        render(:template => 'instructor_home')
      end
    
      def student_home
        # ...
        render(:template => 'student_home')
      end
    
      def admin_home
        # ...
        render(:template => 'admin_home')
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On my site, I have three roles: Role 1 Role 2 Role 3 Role
Basicall I have three Tables Users Roles and USerRoles with Many to many Relationship.
i have three lists with the same number of elements in each other, i
I'm using linq to SQL along with asp.net membership provider. I have three roles
Is it possible to deploy multiple roles in the same instance? I have three
I have three tables: Login, LoginRoles and Roles. Login joins to LoginRoles and LoginRoles
I have a User and Company model. There are three possible roles that a
Suppose I have multiple roles, each one defining a set of items: package A;
I have three tables in my sample database: Users ID Username Password Roles ID
I am slightly confused on how to setup my table. I have three roles

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.