Skip to content

ozataman/acts_as_bucket_on

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ActsAsBucketOn
==============

This is a plugin created out of practical necessity to form groupings, a.k.a. buckets, from the results of a query.

The plugin currently has only minimal functionality, but it works. I plan to add and expand on the idea, as this is
much needed functionality in many applications.

Please feel free to suggest ideas, provide feedback or complain at:

ozataman-at-gmail.com

Example
=======

class Task < ActiveRecord::Base
	acts_as_bucket_on :horizon, :conditions => "self.due_at.strftime('%y%m%d')"
end

@tasks = Task.all
@buckets = Task.bucket_by_horizon(@tasks) # => {'20090305' => [<Task>,<Task>,...], '20090306' => [...]}
	
Now you can easily list tasks from each day separately in your views without having to apply any further processing on them:

<% @buckets.keys.each do |key| %>
<h1>Tasks due <%= @buckets[key].first.due_at %></h1>
.
.
.
<% end %>

Copyright (c) 2009 [Ozgun Ataman], released under the MIT license

About

An ActiveRecord plugin that groups query results into buckets.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages