How can I model a book in a MVC. I’m using Ruby on Rails.
A book has chapters, and chapters has pages.
Should I use a book as a model, or should there be seperate model each for book, chapter and then pages.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The most natural way of doing this is:
book.rb
chapter.rb
page.rb
Then in whatever view you are when you call your book (haml):
and you can paginate however you see fit.
EDIT
To @apneadiving point, added includes for N+1 queries. So from your books_controller.rb, to reduce the number of queries, you can call:
This will load the Book with all of its associated chapters and pages without having to do additional queries.