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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:58:11+00:00 2026-05-20T09:58:11+00:00

I have a player, game, shot, round and team model. When creating a shot,

  • 0

I have a player, game, shot, round and team model.
When creating a shot, it belongs_to a all of those models. (This is because a team does not always have the same players, but reasons are unimportant.)
My game form accepts_nested_attributes for rounds and my rounds accepts_nested_attributes_for my shots (of which there are always 6 — 3 on each team)

To summarize, I have a nested form for game => rounds => shots and I need shots to have a round_id, player_id, team_id and game_id.

Should I use f.hidden_field, and if so, isn’t that dangerous? Even if I so how do I wire it so that the ids are in the right place?

I posted the views below, if anything else is needed let me know.

rounds/_form.html.erb

<% if @round.errors.any? %>
  <div class="error">
    <% @round.errors.full_messages.each do |msg| %>
      <%= msg %><br/>
    <% end %>
  </div>
<% end %>

<%= form_for @game do |f| %>
  <%= field_set_tag "#{@game.away.name} at #{@game.home.name}" do %>
    <table class="sortable">
      <thead>
        <tr>
          <th>Number</th>
          <th><%= @game.away_players[0].name %></th>
          <th><%= @game.away_players[1].name %></th>
          <th><%= @game.away_players[2].name %></th>
          <th><%= @game.home_players[0].name %></th>
          <th><%= @game.home_players[1].name %></th>
          <th><%= @game.home_players[2].name %></th>
          <th>Remove</th>
        </tr>
      </thead>
      <tbody>
        <%= f.fields_for :rounds do |round_form| %>
            <%= render 'round_fields', :f => round_form %>
        <% end -%>
      </tbody>
    </table>

    <p>
      <%= link_to_add_fields "Add Round", f, :rounds %>
    </p>

    <p>
      <%= f.submit %>
    </p>
  <% end %>
<% end %>

rounds/_round_fields.html.erb

<% 6.times { f.object.shots.build } if f.object.new_record? -%>
<tr>
  <td>
    <%= f.text_field :number, :size => 3 %>
  </td>

  <%= f.fields_for :shots do |shot_form| %>
    <%= render 'shot_fields', :f => shot_form %>
  <% end -%>

  <td>
    <%= f.check_box(:_destroy) %>
    <%= f.hidden_field :id %>
  </td>
</tr>

rounds/_shot_fields.html.erb

<td>
  <%= f.select :cup, [["Miss", 0], 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ["Suicide", 11]], :include_blank => "No Shot" %>
  <%# f.hidden_field :id %>
</td>
  • 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-20T09:58:12+00:00Added an answer on May 20, 2026 at 9:58 am

    Maybe session vars that point to the required variables could work.

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

Sidebar

Related Questions

I have code like this to move the player in my game left, right,
I'm working on a player inventory system for a game. I have a struct
So, i'm attempting simple card game. I have player class with draw function, and
Background: I have a bird view's JavaScript game where the player controls a space
I have a class that contains player numbers... public class Game { public int
Lets say we have a two players game, where one player always wins (there
Question about how to perform a django query. I have a Game model with
How can I have that functionality in my game through which the players can
I have a flash player that has a set of songs loaded via an
I have three (C++) classes: Player, Hand, and Card. Player has a member, hand,

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.