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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:57:06+00:00 2026-06-14T06:57:06+00:00

I am just trying to make my form display a blank field for each

  • 0

I am just trying to make my form display a blank field for each item that has not yet been created. I’ve done this successfully using the build method for more simple forms but I’m not sure how to do it for this case. Is the strategy I’m using to do this wrong or am I making a simple syntax mistake?

Here’s the basic model setup:

A Comp has many Rounds and many Teams. A Round has many Items. Each Team has only 1 Item per Round

So when the form is loaded, if a team has not already created an item, I want there to be a blank item created for that team so that it shows up in the form and can be edited for that team.

I tried 2 different methods in my controller and neither has worked:

Method 1:

def edit_admin
    @comp = Comp.find(params[:comp_id])
    @round = @comp.rounds.find(params[:round_id])  
    team_ids = @round.items.all(:select => :team_id).collect(&:team_id)
    @comp.teams.each do |team|      
        if team_ids.include? team.id == false
            new_item = @round.items.new(:team_id => team.id, :round_id => @round.id)
            new_item.save        
        end
    end
end

def update_admin
    @comp = Comp.find(params[:comp_id])
    @round = @comp.rounds.find(params[:round_id])     
    if @round.update_attributes(params[:round]) 
        redirect_to(edit_comp_path(@comp))
    else
        render 'edit_admin'    
    end    
 end

Method 2:

Essentially the same thing but I defined a method to run before the page loads:

before_filter :build_new_items, :only => :edit_admin 

private
    def build_new_items
        @comp = Comp.find(params[:comp_id])
        @round = @comp.rounds.find(params[:round_id])
        team_ids = @round.items.all(:select => :team_id).collect(&:team_id)
        @comp.teams.each do |team|      
            if team_ids.include? team.id == false
                new_item = @round.items.new(:team_id => team.id, :round_id => @round.id)
                new_item.save        
            end
        end
    end

The form looks like this (the view is called edit_admin.html.erb):

<%= form_tag update_admin_comp_round_items_path(@comp,@round), :method => :put do %>
    <% for item in @round.items.all %>
        <%= "Team: " + @comp.teams.find(item.team_id).team_name %> <br />
        <%= fields_for 'round[items_attributes][]', item do |f| %>
            <%= f.label :item_name %>
            <%= f.text_field :item_name %> <br />
            <%= f.hidden_field :id, :value => item.id %> <br />
        <% end %>
    <% end %>  
    <p><%= submit_tag "Submit" %></p>
 <% end %>

Thanks.

  • 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-14T06:57:07+00:00Added an answer on June 14, 2026 at 6:57 am

    Answering my own question since no one else did: I got method B to work with a very minor tweak. All it needed was parentheses around the value after “include?”, like so:

    if team_ids.include?(team.id) == false.

    I figured this out by playing with each line of code in the rails console.

    Method A may work as well but since I got method B to work, I haven’t yet tried it.

    UPDATE: method A also works

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

Sidebar

Related Questions

How can I disable tinyMCE? I'm not trying to make tinyMCE not exist, just
I'm trying to make a set of custom tags that encapsulate form elements (markup
I'm trying to make a web page that only has content within the page
I am trying to make a form that lets the user choose a date
I am trying to make a form building tool. Everything was working just fine.
I am just trying to make a vector, but it gives me a huge
I'm still picking up ObjC and I'm just trying to make sure I understand
I just went through trying to make an alarm clock app with local notifications
I am just messing around trying to make a game right now, but I
I'm trying to make a RLE (Run-Length Encoder) Programme just for characters. I read

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.