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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:48:54+00:00 2026-05-26T05:48:54+00:00

I’m designing an application that has two [three including administrators] user types: Buyers and

  • 0

I’m designing an application that has two [three including administrators] user types: Buyers and Sellers. When a user signs up, it’s assumed that they’re signing up to simply purchase something [a Buyer account]. However, if they wish to become a Seller, there should be an option for them to post their items for sale, [become a Seller]. This becomes important, as users can switch back and forth between account types.

Of course, a Seller can buy items as well.

The problem

The problem I’m facing is that Sellers have profile pages where buyers can go to view their items for sale, whereas Buyers do not. However, both user types have a My Account page that they can use to update their information.

Possible design choices

Single table inheritence

class User < ActiveRecord::Base
  has_one :profile
end

class Seller < User
  has_many :sale_items
end

class Buyer < User
  # nothing here.. I guess this is the "default" user type
end

I thought about this approach because then I could clearly separate the user types. For example, the show page for each user is clearly separated. However, this could lead to repeated code in each controller, and introduce a problem when switching between user types.


Just use declarative_authorization or CanCan to add functionality to the base user type

class User < ActiveRecord::Base
  has_one :profile
  has_many :sale_items  # only for Sellers
                        # if the user is a seller, allow them to add sale_items
end

I thought of this approach because a Seller is basically a Buyer with additional functionality, such as posting items for sale. This could lead to a lot of view logic, though. For example if @user.role == "seller" render _some_seller_partial. I also don’t like the idea of checking for a hard coded string in the view. Well, I guess I could do if @user.seller?

Other design choices?

I’m really interested in hearing how other people would model this application. I’ve been thinking about this for a couple days now.

  • 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-26T05:48:55+00:00Added an answer on May 26, 2026 at 5:48 am

    I would use the second option, but with declarative_authorization instead of cancan, and I’d use the role_model Gem to store the role in the user model.

    class User < ActiveRecord::Base
      has_one :profile
      has_many :sale_items  # only for Sellers
                            # if the user is a seller, allow them to add sale_items
    
      #  t.integer :roles_mask , :default => 0    # for role_model
    end
    

    declarative_authorization is a bit more powerful than CanCan, and I found it to scale better once a project needs more / more complex roles..

    If you store your roles using the role_model Gem, it stores them as a bitmap in the roles_mask attribute.
    This means that a user can have many roles, e.g. can be a Seller and a Buyer at the same time, and an Admin or Moderator if you like.

    See:

    http://railscasts.com/episodes/188-declarative-authorization

    http://railscasts.com/episodes/189-embedded-association

    http://railscasts.com/episodes/192-authorization-with-cancan

    http://railscasts.com/episodes/193-tableless-model

    And:

    http://everydayrails.com/2011/10/06/rails-authorization.html

    http://www.tonyamoyal.com/2010/07/28/rails-authentication-with-devise-and-cancan-customizing-devise-controllers/

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post

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.