Because thatβs a reference to the database column in your migration. That line basically says, βWhen the :next_chapter method is called, return the chapter that lists this one as its :previous_chapter.β
You could set up the migration to store the next chapter instead of the previous one. Itβs the same process. I just thought it makes more sense this way because when you create a chapter, the previous one probably exists already, whereas the next one might not.
Thanks Brian for the reply!
Why is the
foreign_keytheprevious_chapter_idand not something likenext_chapter_id?Because thatβs a reference to the database column in your migration. That line basically says, βWhen the
:next_chaptermethod is called, return the chapter that lists this one as its:previous_chapter.βYou could set up the migration to store the next chapter instead of the previous one. Itβs the same process. I just thought it makes more sense this way because when you create a chapter, the previous one probably exists already, whereas the next one might not.
Ahhh clever, thanks Brian for the help. I implemented this method and it worked as you described it :)