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

  • SEARCH
  • Home
  • 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 7609027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:04:19+00:00 2026-05-31T01:04:19+00:00

I am writing ruby on rails application, which will have 2 different users types

  • 0

I am writing ruby on rails application, which will have 2 different users types (let’s say sellers and buyers). I am using devise gem to handle authentication.

I don’t want to use single table inheritance for 3 reasons:
1) I don’t want to have a lot of columns in my user table (I would have to store fields for both seller and buyer in one table, and they will have a lot of different fileds)
2) I don’t want to have a lot of null values in my database
3) Keeping sellers and buyers separated will help to improve performance speed

I decided to create 2 separate models for sellers and buyers (and generate devise for each of them). Long story short – it caused some troubles (ie. difficulties with handling login with single form, using polymorphic associations for simple things like “private message”, keeping my code DRY etc.)

So here is the question:
Do You think it would be good idea to create one model (user) with some common fields to easily handle authentication with devise and then have separate models (sellers and buyers) with belongs_to and has_one associations to store more info. Something like this:

class User < ActiveRecord::Base
  has_one :seller
  has_one :buyer
end

class Seller < ActiveRecord::Base
  belongs_to :user, :conditions => "user_type= 'seller'"
end

class Buyer < ActiveRecord::Base
  belongs_to :user, :conditions => "user_type= 'buyer'"
end

Is that a good solution? Or do You think single table inheritance would be a better idea?

What troubles / difficulties it may cause?
What will be routes for displaying profile page for each user? I would like to have something like website.com/sellers/id and website.com/buyers/id

If You can think of better solution for my problem – please let me know.

  • 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-31T01:04:21+00:00Added an answer on May 31, 2026 at 1:04 am

    It would be even better if you create seperate tables for Seller and Buyer and use polymorphic association like there Inheritance and polymorphic-associations in rails.

    Seperating these two things you will gain speed in DB queries and keeping the Seller and Buyer logic on their own classes also is very good practice.

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

Sidebar

Related Questions

I have an application using Ruby on Rails where a user will be providing
I am writing a Ruby on Rails app. which will use a 3rd party
I am planning on writing a rails application which will distribute tasks to several
I am writing a web based application using Ruby on Rails. In one of
I am about to be writing a Ruby on Rails app which will use
I'm writing a ruby on rails application using mongoid and I'm wondering about the
In a fit of unoriginality, I'm writing a blog application using Ruby on Rails.
Hi I need to build an ruby on rails application which will call every
I’m writing an application with Ruby on Rails. This application will be delivered to
I'm writing a non-Rails ruby application (gasp!) and would like to be able to

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.