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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:19:08+00:00 2026-06-12T19:19:08+00:00

I have a simple nested form using the ‘nested_form’ gem. It looks like this:

  • 0

I have a simple nested form using the ‘nested_form’ gem.

It looks like this:

<%= nested_form_for @user do |f| %>

  <%= f.text_field :username, :size => 25 %>

<%= f.fields_for :teams do |team_form| %>
  <%= team_form.label :team_name, 'Name of your team' %>

<% end %>
<%= f.submit :value =>'submit' %>
<% end %>

Now I want to prefill the fields in my new-action. While it’s easy to fill the username-field with @user.username = "someone" I have no idea how to access the first nested field “team_name” in the nested “team_form”.

In the html the field looks like this:

<input id="user_teams_attributes_0_team_name" type="text" name="user[teams_attributes][0][team_name]">

Any ideas how to prefill this nested field?

  • 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-12T19:19:09+00:00Added an answer on June 12, 2026 at 7:19 pm

    Typically build can be used for this in your controller (as it doesn’t cause a save on the @user object), appending new Team instances to the :teams collection on the @user object. In your action

    @user = User.new
    @user.teams = [ Team.build(...) ]
    

    where ... contains the default attributes for @user.teams.first that will be displayed in the nested form.

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

Sidebar

Related Questions

I have a nested form in a rails view that is called like this
I have a nested form in a Rails 3.1 app, using Cocoon gem. In
I have a form created using the simple_form gem which populates 2 models using
I currently have an input form generated using Cocoon and would like to make
I'm using the CodeIgniter PHP framework. I have a simple form that has an
I have a simple structure in mongodb, with nested array. How can I update
I have simple php validation form that is halfway working. If you leave the
I thought that there should have been a simple solution to this, given that
I am trying to create my app using the Nested Set Gem here I
I am having trouble with my nested form. I am using Ryan Bates' code.

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.