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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:03:27+00:00 2026-05-12T08:03:27+00:00

I hope my question is understandable, else I’m glad to clarify. We have this

  • 0

I hope my question is understandable, else I’m glad to clarify.

We have this sport event coming up, and I have the pleasure to register the people. 🙂

Facts:

  • one can have a team of 5-10 persons.
  • Need to know the order in which the people start.
  • Need to know who the team leader is.

I did a form in the following style:

  1. o [____Write first name here___] <— this is a textfield
  2. o [____Write second name here__]
  3. o [___________ ... ____________]
  4. …

the “o” is a radio-button, used to pick the team leader.

I have a model Person and a model Team. Every team has a leader_id (which is one of the Person IDs). Furthermore every team :has_many persons.

In the controller I have

def create
   @team = Team.new(params[:team])
   @team.save #just assume there are no errors
end

In the view I have (for the radio-buttons):

<input id="team_leader_id_**????**"
       name="team[leader_id]"
       type="radio"
       value="**????**"
/>

<input id="team_leader_id_**????**"
       name="team[leader_id]"
       type="radio"
       value="**????**"
/>    
# etc.

My question: What should I put at **????** ?

I don’t know the IDs of the persons yet, as they haven’t been created. I have to put some meta-ID there, which ruby on rails recognizes and links everything correctly?

You don’t have to read the rest (it describes the hack I’m using)

As said, at the moment I’m doing an ugly hack: first save the Team (without generating a leader), then fetch the same team from the db, get its people, and find the first person matching the value of

params[:team][:leader_id].

Finally saving this person’s ID in the field of leader_id of the team.

But this code is inefficient, huge and buggy, that I suspect there is an easier way.

  • 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-12T08:03:27+00:00Added an answer on May 12, 2026 at 8:03 am

    The radios should have the same name i.e.

    <input id="team_persons_attributes_0_leader_id"
           name="team[persons_attributes][leader_id]"
           type="radio"
           value="0"
    />
    <input id="team_persons_attributes_1_leader_id"
           name="team[persons_attributes][leader_id]"
           type="radio"
           value="1"
    />
    <input id="team_persons_attributes_2_leader_id"
           name="team[persons_attributes][leader_id]"
           type="radio"
           value="2"
    />
    

    This way there can only be one selected (via the browsers internal radio button mechanism) and params[:team][:persons_attributes][:leader_id] will contain an index to params[:team][:persons] which will be the leader’s name.

    to obtain the id

    team = Team.create(params[:team])
    params[:team][:persons].each_with_index{|name, idx|
       person = Persons.create(:name => name)
       #assuming no errors
       team.leader_id = person.id if params[:team][:persons_attributes][:leader_id] == idx
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope this question is not 'controversial' - I'm just basically asking - has
I hope this question is not a duplicate but I didn't find anything equivalent
I hope this question isn't too open ended, but a nudge in the right
I hope this question will not be rejected as there is no code. But
dudes. I hope this question is not a repost. I'm newbie on Kohana. I'm
I hope this is a quick question I hope. I need to write some
i have pretty simple simple question (i hope so). How do i change the
hope this will be a quick easy question, I've just tried my app on
(I hope this is a valid question) As I stated in my title, I'm
I hope this question is considered programing related. I've been learning and using .NET

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.