There are several reports in my application, and I'm trying to create a helper method for group_by for all of these collections.
Example:
def group_collection(collection, options = {}) column = options[:column] group_count = collection.group_by{ |item| item.column.strftime('%b %y')} end
This is how I plan to use it
@user_groups = group_collection(@users, :column => "created_at")
Unfortunately this does not work.
undefined method `column' for... [CollectionObject]
Any hints on how to make a column variable an actual column type at runtime so that it considers itself an activerecord column rather than an instance method?
ruby-on-rails activerecord group-by
Amit
source share