0

I have a series of chapters. After a person is finished with that chapter I'd like to link them to the next chapter. By finding the next chapter in that specific course.

Currently I let you start at chapter one by doing:

@course.chapters.first

now when you're done reading the first, I'd like to let you go to the 2nd, after that 3rd and so forth. It obviously has to stop when you have no more chapters to read.

I've tried

link_to 'Next Chapter', @chapter.course.chapters.second 

which works, but obviously it's not dynamic depending on which chapter you're on. Does anybody know how to fix this?

2 Answers2

0

I would suggest to use shift method

2.1.5 :005 > a = [1,2,3]
=> [1, 2, 3] 
2.1.5 :006 > a.shift
=> 1 
2.1.5 :007 > a
=> [2, 3] 
2.1.5 :008 > a.shift
=> 2 
2.1.5 :009 >   a
=> [3] 
dmr
  • 526
  • 2
  • 8
0

Use

@course.chapters.find_nth (curr_chapter + 1)
Wand Maker
  • 18,476
  • 8
  • 53
  • 87