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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:46:51+00:00 2026-05-20T04:46:51+00:00

I have a model that gets treated differently by a parameter it holds, for

  • 0

I have a model that gets treated differently by a parameter it holds, for example its like a character table, which also is used for non player characters, since they share all the same attributes. So it would have a Boolean or integer that would indicate if it was a player character or a non-player character. And non-player characters will be generated automatically with random status parameters and names.

Since the methods used for the two are radically different, I though it would be logical to have a different controller class for them, but that would make a single model have two different controllers, and feels somewhat odd.

Is this bad practice? Should I do all the coding in one controller?

  • 1 1 Answer
  • 1 View
  • 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-20T04:46:51+00:00Added an answer on May 20, 2026 at 4:46 am

    It actually sounds to me like you should have two different models. If the way you interact with the objects is radically different, as you explained, then they really shouldn’t be the same class. Ruby has a great way to deal with this case: Modules. You can use modules to create shared behaviors for objects. You can even store the non-player characters and characters in the same database table by overriding the ActiveRecord table name. For example:

    module Character
      def decrease_hitpoints x
        ...
      end
      # other shared functionality can go here
    end
    
    class PlayerCharacter < ActiveRecord::Base
      set_table_name 'characters'
      include Character
    end
    
    class NonPlayerCharacter < ActiveRecord::Base
      set_table_name 'characters'
      include Character
    end
    

    In this example both PlayerCharacter and NonPlayerCharacter share the same table name and functionality defined in Character, but they are different objects.

    Finally, it’s totally fine to use two or more controllers for a single model, just as it’s fine to build a controller that doesn’t depend on a model at all.

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

Sidebar

Related Questions

How can i have model in knockoutjs that gets its data from an sqlite
I have a model that gets it's view-count updated after it's viewed. This is
I have a GalleryPhoto model with a paperclip attachment that gets processed into a
I have a model that is something like this: class Input(models.Model): details = models.CharField(max_length=1000)
I have a model that holds user address. This model has to have first_name
I have a model called Vote that gets changed very frequently (people voting on
I have a model with an object that contains a collection like this: namespace
I have a scope on my User model that gets users by country scope
I have a model that I would like to serialize to an xml with
I would like to have one model (event) that has multiple polymorphic HABTM associations

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.