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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:00:33+00:00 2026-05-22T19:00:33+00:00

I am getting lots of push back from Rails because I have subclassed User

  • 0

I am getting lots of push back from Rails because I have subclassed User into many different subclasses. In my application, not all users are equal. There’s actually a lot of model objects and not every User type has access to them.

I also need a way to do polymorphic behaviour. For example, many methods will behave differently depending on the type. Isn’t that what polymorphism is for?

But the thing is, I am always getting push back from Rails. The defaults – especially the way forms submit to parameter hashes – seem to work like non-subclassed models. Links and parameter hashes are just two ways in which the defaults really bite you.

What is the “right” way to handle complex logic for different types of Users in Rails? In Java, the subclassing model works – you don’t have to go through hoops to get it to work the way you want to. But in Rails, it’s hard to get subclasses to work with REST conventions, it punishes you when you forget to include :as => :user, or it punishes you when you put a subclassed object in links, such as edit_user_path(@user) <- bad idea!

There’s one other area which is also very hard to deal with. Let’s say I have a Company model and it has many Users. These users can be directors, instructors, trainees, etc – all different subclasses.

When we create the account, we might want to use accepts_nested_attributes_for :users. However, if we use this, we can’t specify the classes that it creates. Bloody hell!

It seems like everything in Rails is designed to not want you to subclass your models. If you don’t subclass, everything ‘just works’. But if you subclass, you are in for hell.

What is the solution?

  • 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-22T19:00:34+00:00Added an answer on May 22, 2026 at 7:00 pm

    Generally speaking, inheritance is discouraged in Ruby in favor of mixin behavior and delegation. Ruby and Rails can do that stuff but it tends to result in the push back you mentioned

    Your particular example sounds like a case for delegation: have a User class which belongs to an employee (or vice versa). The type-specific behavior of that employee (eg director, instructor, etc) is all in that specific employee class. Then the user will delegate how to handle specific scenarios to the employee that it’s joined with

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

Sidebar

Related Questions

I have an application that uses several instances of getJSON, and I'm getting into
I have been tasked with writing an ADP application using Access. The back-end data
Getting lots of additional whitespace in the html output, looks like its because of
I've noticed RAII has been getting lots of attention on Stackoverflow, but in my
I bought a new Vista PC recently but was having lots of problems getting
Getting the subdomain from a URL sounds easy at first. http://www.domain.example Scan for the
Just getting my head around Linq and having lots of fun! Can any one
I've had lots of success in getting IE to play nice in the past,
I have a web-form that is getting customer information. The form is processed using
I've had lots of problems getting a simple UIImagePicker working (see my other posts),

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.