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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:58:03+00:00 2026-06-15T10:58:03+00:00

Im looking for the following thing: an array of all users (only 6 in

  • 0

Im looking for the following thing: an array of all users (only 6 in this case) with a checkbox in front of their name, resulting in a list of selectable players for the game.

Current code:

<%= form_for @game, url: games_path, :method => "post" do |f| %>
    <%= f.label :name %>
    <%= f.text_field :name, :value => "#{current_user.name}\'s Game" %>
    <%= f.fields_for :participants do |ff| %>
        <%= ff.label :user_id %>
        <%= ff.text_field :user_id %>
        <%= ff.check_box :user_id %>
    <% end %>
    <%= f.submit "Create Game", class: "btn btn-primary" %>
<% end %>

I’m now having 3.times { @game.participants.build } in my controller which effectively gives me 3 textfields in which i can fill in the participant id in order to make a record in the table participants (which is linked to games).

I’ve been looking around for 1.5h now and i cant seem to find a proper answer. What i need is a syntax that gives me a list of all current users (say @users) with a checkbox attached to it. When I click the checkbox it should add its id to the parameters and i should be able to create a new game with the linked participant id’s. However I’m getting some problems with the ID’s attached to the check_box which always seems to be 1. I’ve read some stuff about checkboxes being a pain with hashes, but I have no other solution atm.

I tried:

<% @users.each do |i| %>
        <%= check_box_tag "alternate_numbers[#{i}]" %> <%= i.name %><br />
<% end %>

But i see no way to get that fixed up part of the form itself.

GamesController code (edit):

def new
    @users = User.paginate(page: params[:page])
    @games = current_user.games
    @game = Game.new
    3.times { @game.participants.build }
  end

def create
    @game = Game.new(params[:game])
    @newround = @game.rounds.new
    @newround.storyFragment = "New story!"
    if @game.save && @newround.save
      flash[:success] = "Created!"
      redirect_to game_path(@game.id)
    else
      redirect_to root_url
    end
  end

It’s very vague to describe since im not exactly sure how to accomplish this.

In short: the check_box should contain the value of the user_id in the loop. I’m now filling in a manual ID with the text_field helper but i’d like to have the checkbox linked to the username that is right next to it in the view.

Any guidelines/solutions/tips?

Thx

  • 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-15T10:58:04+00:00Added an answer on June 15, 2026 at 10:58 am

    Okay, so you’re making a form for a new Game. You now have to feed that new Game, along with some Participants to your view.

    def new
      @game = Game.new
      @participants = User.all # or the users you want
    end
    

    Now use those in your view. You were on the right track. Depending on how your create action works:

    <% @participants.each do |p| %>
      <%= check_box_tag "participants[#{p.id}]" %> <%= p.name %>
    <% end %>
    

    I think what you were missing was the documentation for check_box_tag. The input attribute name is the argument.

    You also seem to have a lot of logic in your controllers. Remember to keep the logic in the models, and only use the controllers to give the right objects to your views, and taking them for saving, for example. As the saying goes, “fat model, skinny controller”.

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

Sidebar

Related Questions

Looking in this StackOverflow question it uses the following to send emails: System.Net.Mail.SmtpClient Is
I'm looking for the following solution in PHP. Whenever a user clicks on a
I was looking at the following code I came across for printing a string
I was looking at the following code in python: for ob in [ob for
I'm looking at the following API: http://wiki.github.com/soundcloud/api/oembed-api The example they give is Call: http://soundcloud.com/oembed?url=http%3A//soundcloud.com/forss/flickermood&format=json
Trying to customize Symfony2 form to produce html code looking like the following example:
I come from ruby/C# and am new to Python. I'm looking at the following
Using the following query I am looking for a solution to get the latest
Im looking for a mobile SDK that has the following for iOS and Android
I am looking to accomplish the following and am wondering if anyone has 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.