I have a model called note. I am currently receiving notes like this:
current_user.notes.order('date DESC, created_at DESC').limit(10).reverse!
Now I need to do the following: Take the note_id parameter and return 10 notes: one of the parameter and 9 others "around" the first.
Ideally, 9 other notes will be highlighted as 5 before the main recording and 4 after (or 4 before and after 5 after) based on the order in the first line above.
Example:
note note note note primary_note note note note note note
Sometimes this is not possible. For example, if primary_note is the second user entry, it should return this:
note primary_note note note note note note note note note
Or, if the last note, and the user has only 3 notes, he should return:
note note primary_note
How can i do this? I am using ruby 1.9.2 and Rails 3.0.1
source
share