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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:13:12+00:00 2026-06-16T21:13:12+00:00

I have 2 models user and team. a team can have many users each

  • 0

I have 2 models user and team. a team can have many users each users belong to a team.

team_id is a column in my user table as a fk.

I want to have a select drop down on my create user form that has all my teams team_id in it.

This code does what I want BUT

 <%= f.fields_for :teams do |builder| %>
    <p>
        <%= f.label :team_id, "Select Team For User" %>
        <%= builder.collection_select :team_initials, Team.all, :id, :team_initials %>
    </p>
<% end %>

it does not try to add the id value to a user. here is the error

    Parameters:
{"utf8"=>"✓",
 "authenticity_token"=>"xxxxx",
 "user"=>{"name"=>"brand new",
 "email"=>"test1@test.com",
 "password"=>"[FILTERED]",
 "password_confirmation"=>"[FILTERED]",
 "teams"=>{"team_initials"=>"27"}},
 "commit"=>"Create my account"}

It complains that it cant add to the team model.

All I want to do is grab the ID of all existing teams for my create user form so when you crate a user you can select that users team.

The reason I have team_initials above is I was trying to use a more user friendly field for select but still user team Id as the value.

  • 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-16T21:13:13+00:00Added an answer on June 16, 2026 at 9:13 pm

    I think you’re on the right track. The fields_for mechanism is for setting values in the associated model. I think all you’re trying to do is make the association.

    So you can lose the fields_for line and then this section:

    builder.collection_select :team_initials, Team.all, :id, :team_initials
    

    Should be:

    f.collection_select :team_id, Team.all, :id, :team_initials
    

    I’m looking here for my info on collection_select since I don’t know it off the top of my head:
    http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html

    I think this will change this parameter from "teams"=>{"team_initials"=>"27"}}, to "team_id"=>"27",

    I hope that fixes it.

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

Sidebar

Related Questions

I currently have the following models: class Player < ActiveRecord::Base belongs_to :team belongs_to :user
I currently have a model for team.rb and user.rb, which is a many to
I have 3 models: user, seller and cars i want the user to be
I have several models: User = an ordinary user class (does not belong to
I have three entities: User , Team , and TeamInvite . Each User has
I have two models: User and Car with the following associations: User has_many Car
I have two models User and Category that have a HABTM association. I would
I have 2 models: User and Book and a join model ownership which connect
I have three models: User Image Group . User belongs to an image; Group
I have two models -- User and Entry -- that are related through a

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.