0.0
No commit activity in last 3 years
No release in over 3 years
groups the record on basis of created_at
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
>= 0

Runtime

~> 4.0.0
 Project Readme

group_records

Tested with Rails 4.0.0 and Ruby 1.9.3.

Use this gem to group ActiveRecord::Relation objects by Month or Year.

PS - You must have a created_at column in the database table to use this gem.

This gem provides two methods which returns hash having keys as month or year and value as array of all the objects for that month or year.

  1. group_by_month
  2. group_by_year

The order of the keys returned are sorted on the basis of created_at.

Example Usage -

class PostsController < ApplicationController
  def index
    @posts = Post.all
    @posts_months = @posts.group_by_month
  end
end

Or more succinctly

@posts_months = Post.all.group_by_month

viewing @posts_months in rails console -

{"January 2014"=>[#<Post id: 8, title: "sample">]}