0

I have a model:

entry (created_at: datetime, temperature: float, melt_type: string)

I need to paginate entries by cycle (rather than a set number of entries).

A cycle is defined by the first entry with any melt_type value to the last entry before another melt_type is entered. (melt_type appears for a few days at the beginning of a cycle lasting ~40 days, but won't appear any other time in a cycle).

I've found a few pagination gems (will_paginate or Kaminari), but am having difficulty finding a solution that doesn't use an exact number of entries per page.

1 Answers1

0

I was thinking of this the wrong way.

What I really needed was to create a single table inheritance in which I created a new model called melt_cycle that inherits from entries instead of the ActiveRecord::Base.

It does require the user to designate the beginning of the melt_cycle, but that's not unreasonable.

Now I just need to figure out how to automatically assign entries to ID of the previous melt_cycle_start

Now my entry model looks like (created_at: datetime, temperature: float, melt_type: string, melt_cycle_start: boolean)

Here's a great tutorial from Team Treehouse on Single Table Inheritance: http://teamtreehouse.com/library/rails-models/migrations-and-relationships/single-table-inheritance