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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:47:35+00:00 2026-05-31T21:47:35+00:00

Rails newbie here struggling with a small project. I am creating a simple ship

  • 0

Rails newbie here struggling with a small project. I am creating a simple ship building tool for a board game I like as an exercise and I am a bit lost.

What do I want to do?
-After creating my Ship model record I want to create the Traits model record that will be associated with the Ship model. After updating a Ship model record I want to update or create the Traits model that will be associated with the Ship model record.

What have I tried?
– Adding the traits to each Ship model record as column variables. I do not think that this is the most effecient way of storing the traits for each of my Ship models. I have a Traits model set up but I do not know how to navigate to it and associate it with my Ship models

What would I like to have when finished?
– An array that is stored in each Ship model record that will list the attributes for each ship with their corresponding values,

i.e. if

trait_list = [trait1 => t1, trait2 => t2, trait3 => t3, trait4 => t4]

ship_traits = [t1, t4].

In the end I would be able to call the traits on my ship diagram page without having to iterate through every single trait, just the ones pertinent to my current model.

I am lost on how I should set up the associations between the models. Any help or kind advice on directions I should be researching would be warmly welcomed. I apologize in advance for my vagueness, again I am a complete newbie.

Cheers,
Nick

  • 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-31T21:47:36+00:00Added an answer on May 31, 2026 at 9:47 pm

    I’m not 100% sure this would solve your problem, but you could do something like this:

    class Ship < ActiveRecord::Base
      has_many :traits
      accepts_nested_attributes_for :traits
    end
    
    class Trait < ActiveRecord::Base
      belongs_to :ship
    end
    
    
    # In your form
    - form_for @ship do |f|
      - f.fields_for :traits do |ff|
        = ff.label :trait_name
        = ff.text_field :trait_name
    
    # this will return all the traits for model defined as @ship
    @ship.traits 
    

    I know it’s not an array within the Ship model, but I hear it’s a little tricky to set a column in a model to be array. If you want the traits to be unique (as in many ships can have many traits and these traits can belong to many different ships), then you’re going to have a has_many :through relationship. If that’s the case, let me know and I’ll answer again. Or you can take a look at this: http://guides.rubyonrails.org/association_basics.html

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

Sidebar

Related Questions

Rails newbie here and I'm stumped. In Rails I have a Project Model which
Rails 3 newbie here... I'm working to create a devise auth system that like
Newbie to Rails here, I was wondering if there is a tool which can
Here is one more newbie question: require 'tasks/rails' I saw this line in Rakefile
I'm a Git newbie. I recently moved a Rails project from Subversion to Git.
Rails newbie here so just want to be sure I'm doing this right. I
Rails newbie here. I have a list of items which can have a status
A rails newbie here I have 2 actions in my controller 1) index 2)
Bit of a Rails newbie here so please bear with me. I am trying
Hi (huge Rails newbie here), I have the following models: class Shop < ActiveRecord::Base

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.