How would you setup a model in Rails to reference the same model type?

Michael Lee 🍕 - Jun 11 '19 - - Dev Community

Let's say I have a model for a thing called "Chapter". I want to be able to reference the next chapter and the previous chapter for each chapter. How would you go about setting this up?

So what I'm looking for is something like this:

c = Chapter.first
c.next_chapter
Enter fullscreen mode Exit fullscreen mode

c.next_chapter should return a chapter object that is the next chapter.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player