Previous|next navigation question

When creating “< previous|next >”-type navigation to browse through
records from a list of search results, what is the most efficient (best
practices-) way to determine what the previous and next records are for
a given record?

Should I store the search results array and the position (index) of the
current record in the session?

Or restore the results array each time (running the same search again)
and then determine the position of the current record inside that array
somehow (How can this be done in Ruby)? Sounds very inefficient to me.

Or even add two instance variables (@prev_record, @next_record) to the
record’s model that are populated (with the adjacent records) each time
a search is run, and then store the search results array in the session?

Or …?

Ingo W.

Or subclass the record’s model and add @prev/@next to that subclass,
then use it instead of the original record’s class for searches?

Ingo W.

Ingo W. wrote:

When creating “< previous|next >”-type navigation to browse through
records from a list of search results, what is the most efficient (best
practices-) way to determine what the previous and next records are for
a given record?

What I did was to paginate the model with a per_page value of one.

That way I get a single item on the page and the paginator object
handles the previous/next navigation for me.

Jeff C.man