An ActiveRecord plugin that groups query results into buckets.
License
ozataman/acts_as_bucket_on
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
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 0
No packages published