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

The Archive Base Latest Questions

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

How can I fill in the hidden fields in app/views/rounds/shot_fields.html.erb? app/models/player.rb class Player <

  • 0

How can I fill in the hidden fields in app/views/rounds/shot_fields.html.erb?

app/models/player.rb

class Player < ActiveRecord::Base
  has_many :shots, :dependent => :destroy
  belongs_to :team
  belongs_to :user
  has_many :games
  has_and_belongs_to_many :home_games, :class_name => "Game"
  has_and_belongs_to_many :away_games, :class_name => "Game"
end

app/models/round.rb

class Round < ActiveRecord::Base
  belongs_to :game, :counter_cache => true
  has_many :shots, :dependent => :destroy
  accepts_nested_attributes_for :shots, :allow_destroy => true
  validates_presence_of :number
  validates_numericality_of :number
end

app/models/shot.rb

class Shot < ActiveRecord::Base
  belongs_to :player, :counter_cache => true
  belongs_to :game
  belongs_to :round
  belongs_to :team
end

app/models/game.rb

class Game < ActiveRecord::Base
  has_many :shots, :dependent => :destroy
  has_many :rounds, :order => 'number', :dependent => :destroy
  accepts_nested_attributes_for :shots
  belongs_to :away, :class_name => 'Team'
  belongs_to :home, :class_name => 'Team'

  has_and_belongs_to_many :home_players, :class_name => 'Player', :association_foreign_key => "home_player_id"
  has_and_belongs_to_many :away_players, :class_name => 'Player', :association_foreign_key => "away_player_id"

  accepts_nested_attributes_for :rounds, :allow_destroy => true
end

app/controllers/rounds_controller.rb

def new
    @game = Game.find(params[:game_id])
    @round = @game.rounds.build
    @round.number = @game.rounds.count > 1 ? @game.rounds.count + 1 : 1
  end

app/views/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 "Rounds" 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 %>

app/views/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>

app/views/rounds/shot_fields.html.erb

<td>
  <%= f.select :cup, [["Miss", 0], 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ["No Shot", ""], ["Suicide", 11]] %>
  <%= f.hidden_field :id %>
  <%= f.hidden_field :game_id, :value => params[:id] %>
  <%# f.hidden_field :player_id, :value => player.id %>
  <%# f.hidden_field :team_id, :value => team.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:26:02+00:00Added an answer on May 20, 2026 at 9:26 am

    Passing them in via locals should work.

    <%= render 'shot_fields', :locals => { :f => shot_form, :player => some_player_you_dont_have_defined, :team => some_team_variable_i_dont_see } %>
    

    I don’t quite understand what you’re trying to do (lots of code, not a lot of context), but this is how you pass information into partials.

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

Sidebar

Related Questions

I am creating a HTML layout where user can fill the data and save
Is there an image processing algorithm that can fill these gaps within an image?
I have a from where you can fill in any combination of your home,
In Short: I have a PDF that customers can fill out. When they press
I know in C++ and in PHP you can fill a string or a
I have an ecommerce gift store where users can fill out a gift-card for
I have a table with a form below it. You can fill out the
I'm a pretty new C# programmer. I was wondering if someone can fill me
On a CAShapeLayer , I've drawn a closed UIBezierPath . I can fill this
How can I fill a bitmap in Android with a specific background, with only

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.