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 822261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:46:25+00:00 2026-05-15T02:46:25+00:00

I have a User model in my app, which I would like to store

  • 0

I have a User model in my app, which I would like to store basic user information, such as email address, first and last name, phone number, etc.

I also have many different types of users in my system, including sales agents, clients, guests, etc.

I would like to be able to use the same User model as a base for all the others, so that I don’t have to include all the fields for all the related roles in one model, and can delegate as necessary (cutting down on duplicate database fields as well as providing easy mobility from changing one user of one type to another).

So, what I’d like is this:

User
-- first name
-- last name
-- email
--> is a "client", so
---- client field 1
---- client field 2
---- client field 3

User
-- first name
-- last name
-- email
--> is a "sales agent", so
---- sales agent field 1
---- sales agent field 2
---- sales agent field 3

and so on...

In addition, when a new user signs up, I want that new user to automatically be assigned the role of “client” (I’m talking about database fields here, not authorization, though I hope to eventually include this logic in my user authorization as well). I have a multi-step signup wizard I’m trying to build with wizardly. The first step is easy, since I’m simply calling the fields included in the base User model (such as first_name and email), but the second step is trickier since it should be calling in fields from the associated model (like–per my example above–the model client with fields client_field_1 or client_field_2, as if those fields were part of User).

Does that make sense? Let me know if that wasn’t clear at all, and I’ll try to explain it in a different way.

Can anyone help me with this? How would I do 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-05-15T02:46:25+00:00Added an answer on May 15, 2026 at 2:46 am

    It looks like you have two reasonable approaches here, but it will depend on the nuances of your requirements.

    You can use Single Table Inheritance (STI) to do what you want, where User is only the base class for others named SalesAgent or Client and so forth. Each of these sub-classes may define their own validations. All you need for this to work is a string column called “type” and ActiveRecord will do the rest:

    class User < ActiveRecord::Base
    end
    
    class Agent < User
    end
    

    The alternative is to have a number of free-form fields where you store various bits of related data and simply interpret them differently at run-time. You may structure it like this:

    class User < ActiveRecord::Base
      has_one :agent_role,
        :dependent => :destroy
    end
    
    class AgentRole < ActiveRecord::Base
      belongs_to :user
    
       # Represents the agent-specific role fields
    end
    

    That would have the advantage of allowing for multiple roles, and if you use has_many, then multiple roles of the same type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an app in Rails 3. I currently have a user model which
So I have a User model that :has_many other models like Documents, Videos, Posts
I have a model Foo which have a ForeignKey to the User model. Later,
In my user model, I have an attribute called nickname and validates as such:
I have a data model that includes common columns like addedBy, editedby (user), addedDate,
I'm developing my first iPhone app, and while implementing user preferences, I have a
For example, if I have a user model and I need to validate login
Suppose you have two models, User and City, joined by a third model CityPermission:
I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
I have a basic Ruby app that I am building with Sinatra, Datamapper and

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.