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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:25:24+00:00 2026-06-12T01:25:24+00:00

I have two models, Item and Bid class Item include Mongoid::Document field :name, type:

  • 0

I have two models, Item and Bid

class Item
  include Mongoid::Document
  field :name, type: String
  has_many :bids 
end

class Bid
  include Mongoid::Document
  include Mongoid::Timestamps::Created
  field :bid, type: Float
  field :bidder, type: String
  belongs_to :item  
end

In views/prices/index I would like to list all items in a table and for each item put a field next it in which people can enter a number. At the bottom of the form should be a submit button for all records.

How is this best achieved?

There’s plenty of code out there explaining how to add, for instance, several questions to one survey (http://railscasts.com/episodes/196-nested-model-form-part-1) but I couldn’t find an example that shows how to add one new record for each of an existing element of a collection.

  • 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-12T01:25:26+00:00Added an answer on June 12, 2026 at 1:25 am

    I don’t think you need to dynamically add a form for each item if you know you are going to use all of the items there to begin with.

    Quick and Dirty:

    form_for(@items) do |f|
      @items.each do |item|
        f.label item.name
        f.text_field item.name.to_sym, :value => "1"
      end
      f.submit "Submit"
    end
    

    I haven’t tried this and that code isn’t tested, but I would assume if you do some work in the controller to build each bid it should be fine. Also amount would be a better variable name for the bid class than using Bid.bid.

    The proper way to do this (which would also allow updates) would be to make a nested form and then use fields_for method to actually look at a live bid object: http://archives.ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes

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

Sidebar

Related Questions

I have two domain models: class Resource{ String name static mapping = { sort
I have two models, Landscape: class Landscape < ActiveRecord::Base has_many :images, :as => :imageable
I have two models: class Contact(models.Model): name = models.CharField(max_length=255) class Campaign(models.Model): contact = models.ForeignKey(Contact,
I have two models. order and line_item. class Order < ActiveRecord::Base has_many :line_items has_many
I've got two models: Item and Tag . Both have a name attribute. I
I have a voting system with two models: Item(id, name) and Vote(id, item_id, user_id).
I have two models, Item and ShopSection. They have a many-to-many relationship. @Entity(name =
I have a two models: class Category(models.Model): pass class Item(models.Model): cat = models.ForeignKey(Category) I
I have these two models class Invoice < ActiveRecord::Base has_many :items accepts_nested_attributes_for :items ...
I've got two models Category and Item. Category can have many items and item

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.