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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:58:24+00:00 2026-05-22T12:58:24+00:00

I’m working on a Dungeons and Dragons character database application. I’ve got a Character

  • 0

I’m working on a Dungeons and Dragons character database application. I’ve got a Character model and several models that belong to Character with a has_one association, such as HitPoints, ArmorClass and so on. These are all built, edited and displayed from the Character view. However, I want to create new pages with more information that belongs to the Character model. I want a link at the top of the view that takes the user to an Equipment page, with separate models displayed on that page, such as Weapons, Armor, Gear and so forth.

This is where I need some guidance. Would the Equipment page be a new model that belongs_to Character and I just load models for Weapon, Armor, Gear and so forth into the Equipment view?

If so, would these models have a belongs_to relationship with the Character model, the Equipment model or both?

Finally, if I build it this way: Character has_one Equipment and Equipment has_many Weapons, would the Weapons model also have a belongs_to relationship with the Character model?

Thanks in advance, I hope what I’m trying to do is clear. I’m still having trouble talking about what I want to accomplish with Rails.

  • 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-22T12:58:25+00:00Added an answer on May 22, 2026 at 12:58 pm

    It sounds like you’re misunderstanding some of the concepts around models. For example, HitPoints and ArmorClass should not be models that have a has_one association with your Character. They are just attributes of Character. So your model should look something like this instead:

    class Character
      attr_accessor :name, :hit_points, :armor_class
    
      def initialize(name, hitpoints=10, armor_class=0)
        @name = name
        @hitpoints = hitpoints
        @armor_class = armor_class
      end
      # some other stuff, etc
    end
    

    Then you can access them like so:

    fighter = Character.new("Conan", 100, 12)
    puts "I am #{fighter.name} and I have #{fighter.hit_points} hitpoints."
    puts fighter.armor_class  # outputs 12
    

    Also, I’d say Equipment model is the wrong concept. What you need is an Item model. All of the things you mentioned (weapons, armor, gear) are all just items. And it makes a lot more sense that a “Character” has_many “Items”. Also that “Item” has_many “Characters” since you’ll presumably have multiple characters with multiple items…so it COULD be a many to many relationship to keep it simple. Then your “Item” model could have an “ItemType” field which tells you if it’s a weapon, armor, potion, etc.

    So your Item model could look like this

    class Item
      attr_accessor :name, :type
    
      def initialize(name, type)
        @name = name
        @type = type
      end
    end
    

    Another option, which is closer to what you’re talking about is to add an ItemSet model. We’d put this model between Character and Items. Doing it this way would let you say

    • “Character” has_one “ItemSet”
    • “ItemSet” has_many “Items”
    • Character” has many “Items” through “ItemSet”

    So basically, this is showing that in your “world” you have many characters and items. But each character has a unique set of those items.

    This is the way I’d do it.

    In the code above you need to add the has_many, has_one, etc attributes to the models. I left it out so you could see the models themselves a little easier and so you could figure out how you want to do it yourself.

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

Sidebar

Related Questions

No related questions found

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.