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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:03:12+00:00 2026-05-11T01:03:12+00:00

I’m creating a Rails application, and I’ve hit a bit of a snag. I

  • 0

I’m creating a Rails application, and I’ve hit a bit of a snag. I want a ‘create new record for DataType1’ form that not only creates a new row for DataType1, but also inserts up to four new rows for DataType2.

I know all about fields_for, but my problem is that I need to submit up to four DataType2s, and the only connection they have to DataType1 is that they are referenced via a field in DataType2.

Here’s the simplified database:

create_table :data_type_1 do |t|   t.string     :title   t.text       :body    t.timestamps end  create_table :data_type_2 do |t|   t.belongs_to :parent    t.timestamps end 

Now, I have the relationships all set up and everything; that’s not the problem. The problem is that I just can’t seem to figure out how to pass the params for the DataType2s in with the params for the new DataType1. Once someone shows me how I should go about doing this, I can set up the new DataType2s to associate with the new DataType1 fairly easily.

Here’s what I have for the form at the moment:

<% form_for(@data_type_1) do |f| %>   <%= f.error_messages %>    <p>     <%= f.label :title %><br />     <%= f.text_field :title %>   </p>    # Etc...    <p>     # New items need to be iterated here     # DataType2[1]: [         ]     # DataType2[2]: [         ]     # DataType2[3]: [         ]     # DataType2[4]: [         ]     # (Note that these numbers are just examples.)   </p>    <p>     <%= f.submit 'Create' %>   </p> <% end %> 

I’m relatively new to Rails, and I apologize if this question rambles a bit.

  • 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. 2026-05-11T01:03:13+00:00Added an answer on May 11, 2026 at 1:03 am

    This RailsCast talks about inserting lists of ‘DataType2’ into ‘DataType1’. The interesting parts are these

    app/views/projects/_form.html.erb

      <% for task in @project.tasks %>     <% fields_for 'project[task_attributes][]', task do |task_form| %>       <p>         Task: <%= task_form.text_field :name %>       </p>     <% end %>   <% end %> 

    app/models/project.rb

    def task_attributes=(task_attributes)   task_attributes.each do |attributes|     tasks.build(attributes)   end end 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

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.