0

Hi I am trying to find a simple way to expand my db query and group the records shown by month (Ideally I would like next month stored in "Next Page"). Is there a way to do this?

Current query

@submissions = Submission.where(:Desired_Location => current_agent.Company_Business_Location)

Thanks

1 Answers1

0

First get month name from your date field and then use group method to group by month

@submissions = Submission.where(:Desired_Location => current_agent.Company_Business_Location).group('strftime('%m', your_date_field)')

In your case I would suggest to group by year as well. In that case use this:

@submissions = Submission.where(:Desired_Location => current_agent.Company_Business_Location).group('strftime('%Y %m', your_date_field)')
mehedi
  • 466
  • 3
  • 8