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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:28:10+00:00 2026-05-23T10:28:10+00:00

I have a Product Model with the below table which has a ProductsController and

  • 0

I have a Product Model with the below table which has a ProductsController and Form:

    class CreateProducts < ActiveRecord::Migration
      def self.up
        create_table :products do |t|
          t.string  :name
          t.decimal :price
          t.string :location

    end

How can i generate name and price again six times on my form to make six products ( six is a number i just threw out there) in the database?

EDIT: Added the :location to give more of an explanation of what I’m trying to do.

Only on one form Users can create products and can have as many products as they choose ( :name & :price) to be made and all have the same :location when they submit the form. This is basically a way to do Nested Models but with one table only ( including the Railscast Ajax, i will put this in myself).

  • 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-23T10:28:11+00:00Added an answer on May 23, 2026 at 10:28 am

    Rails has support for input arrays. Things like products[] can be submitted to the controller

    Otherwise, you’d run into issues submitting a form with inputs with the same name and ID. You could bundle all the inputs up into a Javascript array and submit that via POST.

    If you’re using jQuery, you could name all your product name inputs like this:

    <input class="product_name" type="text">
    <input class="product_name" type="text">
    <input class="product_name" type="text">
    

    do something like

    var products_array = [];
    $(".products").each(function() {
      products_array.push($(this).val());
    });
    

    Out of curiosity, why do you want to enter multiple product on one page? Is this like an invoice type thing?

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

Sidebar

Related Questions

I have a model class as shown below: class Product < ActiveRecord::Base belongs_to :user;
I have a users_manager engine which has a User model class. In an other
I have a Product and a Benefit class which is shown below: Now, I
I have Product model and it has many categories with a has_many :through association
In Django, I have two models: class Product(models.Model): name = models.CharField(max_length = 50) categories
Let's assume I have a model called product. Let's assume that product has three
I have a product which has been traditionally shipped as an MSI file. It
Below is simplified example of what I am trying to achieve: class Product(models.Model): #
Let's say I have this model named Product with a field named brand .
I have two models, say Product and Bundle. products table is related to product_prices

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.