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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:53:55+00:00 2026-06-02T10:53:55+00:00

I have been trying to create a basic rails application. I used generate to

  • 0

I have been trying to create a basic rails application. I used generate to create a basic scaffold and I have setup a belongs_to relationship between players and teams so players belong_to team and team has_many players.

My form view looks like this

<%= form_for(@team) do |f| %>
  <% if @team.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@team.errors.count, "error") %> prohibited this team from being saved:</h2>

      <ul>
      <% @team.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :Playerone %><br />
    <%= f.collection_select :Playerone, Player.all, :firstname, :firstname %>
  </div>

  <div class="field">
    <%= f.label :Playertwo %><br />
    <%= f.collection_select :Playertwo, Player.all, :firstname, :firstname %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

When I try to create a new team I get the dropdowns as I want them with the players first name to select from but then when it is saved it saves 0 as the record.

Listing teams

Playerone Playertwo
0 0 Show Edit Destroy

New Team

Originally I had the collection select like this
<%= f.collection_select :Playertwo, Player.all, :id, :firstname %>
This inserts the ID but I want the text to be inserted instead.

I have looked over reams and reams of documentation and have come up trumps as I am still learning.

Thanks for any help 🙂

  • 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-06-02T10:53:57+00:00Added an answer on June 2, 2026 at 10:53 am

    Then it depends on your migration. If you created an integer field in your database, saving the string will save 0.

    You can (a), change your migration to use a string instead of an integer.

    You can (b), use the id, and display the name by looking up the name.

    f.collection_select :Playertwo, Player.all, :id, :firstname
    

    You can either get the name from the team belongs_to playerone and playertwo,

    class Team
      belongs_to :playerone, :class_name => "Player"
      belongs_to :playertwo, :class_name => "Player"
    end
    
    <%= team.playerone.firstname %>
    

    or you can delegate the firstname to the players.

    class Team
      belongs_to :playerone, :class_name => "Player"
      belongs_to :playertwo, :class_name => "Player"
      delegate :firstname, :to => :playerone, :prefix => true, :allow_nil => true
      delegate :firstname, :to => :playertwo, :prefix => true, :allow_nil => true
    end
    
    <%= team.playerone_firstname %>
    

    Or you can (c) use the belongs_to, which uses an integer. Please look up the documentation
    http://guides.rubyonrails.org/getting_started.html

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

Sidebar

Related Questions

I have been trying to create a menu panel with jQuery that can be
I have been trying to create a new google custom search engine, but when
I have been trying to create a simple program with Python which uses OpenCV
I have been trying to create an observable tweeter feed using tweetsharp with the
I have been trying to create an XML using the simplexml library (v2.6.2) http://simple.sourceforge.net/home.php
Hi I have been trying to create a crossfade plugin with previous and next
I have been trying to find a good guide to create a templated control.
Ok I'm stumped. I have been trying to use Simpletip to create a tooltip
I'm trying to create a friendship association. I found and have been following the
I am new to open gl, and have been trying to do some basic

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.