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

  • Home
  • SEARCH
  • 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 8722587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:26:58+00:00 2026-06-13T07:26:58+00:00

Model 1 flat invoices table with sales_invoice_date, you_ref amongst other fields Controller def raw

  • 0

Model

1 flat invoices table with sales_invoice_date, you_ref amongst other fields

Controller

def raw
  @invoices = Invoice.find(:all, :order => 'sales_invoice_date, id')
  @invoice_days =  @invoices.group_by { |day| day.sales_invoice_date }
end

View

<% @invoice_days.sort.each do |day, invoices| %>
  <h2><%= day.to_date.to_s(:long) %></h2>
  <% for invoice in invoices %>
  <div class="invoice_line">
    <strong><%= invoice.your_ref %></strong>
    Sales invoice date: <%= invoice.sales_invoice_date.to_date.to_s(:long) %>
  </div>
  <% end %>
<% end %>

This gets me halfway to my objective. It prints the following:

September 9, 2012
    2222 Sales invoice date: September 9, 2012
    5555 Sales invoice date: September 9, 2012
    2222 Sales invoice date: September 9, 2012
October 1, 2012
    1111 Sales invoice date: October 1, 2012
    1111 Sales invoice date: October 1, 2012
    1111 Sales invoice date: October 1, 2012
November 11, 2012
    3333 Sales invoice date: November 11, 2012
December 12, 2012
    0000 Sales invoice date: December 12, 2012

What I need is a way to group_by and sort again within the date loop on unique “your_ref” values, it would look something like this:

September 9, 2012
    2222
        2222 Sales invoice date: September 9, 2012
        2222 Sales invoice date: September 9, 2012
    5555
        5555 Sales invoice date: September 9, 2012

October 1, 2012
    1111
        1111 Sales invoice date: October 1, 2012
        1111 Sales invoice date: October 1, 2012
        1111 Sales invoice date: October 1, 2012
November 11, 2012
    3333
        3333 Sales invoice date: November 11, 2012
December 12, 2012
    0000
        0000 Sales invoice date: December 12, 2012

Thanks

  • 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-13T07:26:59+00:00Added an answer on June 13, 2026 at 7:26 am

    Instead of

      <% for invoice in invoices %>
        <div class="invoice_line">
          <strong><%= invoice.your_ref %></strong>
          Sales invoice date: <%= invoice.sales_invoice_date.to_date.to_s(:long) %>
        </div>
      <% end %>
    

    try:

      <% invoices.group_by(&:your_ref).sort.each do |ref, ref_invoices| %>
        <div class="invoice_line">
          <strong><%= ref %></strong>
        </div>
        <% for invoice in ref_invoices %>
          <strong><%= invoice.your_ref %></strong>
          Sales invoice date: <%= invoice.sales_invoice_date.to_date.to_s(:long) %>
        <% end %>
      <% end %>
    

    This will also group invoices by ref.

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

Sidebar

Related Questions

.386 .model flat, stdcall option casemap:none include windows.inc include kernel32.inc include user32.inc includelib user32.lib
#model class Promotion(models.Model): name = models.CharField(max_length=200) start_date = models.DateTimeField() end_date = models.DateTimeField() #view def
Model: class Session(models.Model): tutor = models.ForeignKey(User) start_time = models.DateTimeField() end_time = models.DateTimeField() def __unicode__(self):
model: User has_one :beta_invite before_save :beta_code_must_exist def beta_code_must_exist if beta_invite_id == beta_invite.find_by_name(beta_invite.id) user else
C's memory model, with its use of pointer arithmetic and all, seems to model
Paperclip gem 3.0.4 When I use flat Paperclip definition in Model (UserDetail has an
I have written a simple program in MASM, like: .386 .model flat, stdcall option
I am basically creating a flat View Model for a Timesheet page (ASP.NET MVC)
Common scenario: Hierachical domain model is being mapped to flat view model for presentation
I have the following assembly code .386 .model flat, c .stack 100h printf PROTO

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.