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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:33:53+00:00 2026-06-06T15:33:53+00:00

I have a data model that represents a weekly order. Eg. my order might

  • 0

I have a data model that represents a weekly order. Eg. my order might be

Monday: 2 x coffee
Tuesday: 2 x tea
Wednesday: 3 x coffee, 4x tea 

I pay for my order at the end of the week.

I represent this as:

Order
   has_many: days

Day
   has_many: line_items

and I have a form of the form:

form_for @order
   fields_for :days
       fields_for :line_items

which Produces a form like

Monday
   Tea x 2
   Coffee x 0
Tuesday
   Tea x 1
   Coffee x 3
Wednesday
   Tea x 1
   Coffee x 2

I want my form to be a table like this:

            Monday     Tuesday     Wednesday

Coffee       2           1           1 
Tea          0           3           2
Add+

I can do this by looping thorough Order.days.each do |day| day.each etc trying to figure out the name of the input field “order[]days[]line_items[]” and adding hidden variables for line_item and day but it’s turning out to be harder than it first looks.

Am I missing a simpler way?

  • 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-06T15:33:54+00:00Added an answer on June 6, 2026 at 3:33 pm

    The way I did it was to build up the form elements in a hash and ad them to the form after

    form_for @order
      fields_for :days
          fields_for :line_items
              hash[line_item.product][day.theday] = select_tag...
    

    then iterate through days and products and put in the appropriate select tag in the table

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

Sidebar

Related Questions

I have an Entity Data Model that I have created, and its pulling in
I have several Core Data model version that I have added to my .xcdatamodeld
I have set up a Core Data model that includes an entity, Item with
I have an Entity Data Model-based app that uses SQL Server CE 3.5 as
I have the following data model: I am writing a WCF service that needs
I have a model that I'm trying to retrieve an array of data from,
In my core data model I have a Person entity that has a to
I have a program that starts up and creates an in-memory data model and
I have a class that contains data from some model. This class has metadata
I have to build an xml output that represents a data structured for a

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.