If you're trying to work with the scaffolding feature of Ruby on Rails, this article series gets you off to a great start. In it, you'll learn how to implement a book inventory management system using this built-in capability. This article is excerpted from chapter three of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).
In this chapter, we will quickly implement a complete book inventory management system using the built-in scaffolding feature of Ruby on Rails. While implementing the system, we will write Ruby on Rails integration tests that exercise the whole book inventory management system from end to end. As we work through this sprint, we will show you how to map database relationships with ActiveRecord, including one-to-many, many-to-one, and many-to-many relationships. Plus, you will learn how to implement file upload functionality with Rails. We’ll also introduce you to the Textile markup language, which can be used to author web content.
Getting the Requirements
To figure out the requirements for this sprint, we ask George what tasks he should be able to perform with the book management system. He tells us that he receives information from publishers about when new books are published and when old ones go out of print. He asks us to build a system that will allow him to update the Emporium book inventory accordingly.
George tells us that he is a big fan of Amazon, even if the giant is eating away at his profits. He likes, for example, the way Amazon is able to recommend books that are similar to what the customer has browsed and bought before, and the small details like the book cover shown next to the details of the book.
We tell George that he at least has to be able to find books in the system, and to view and edit the book details. George confirms that he indeed needs those features. We take a short break, to let George have a coffee. This far into the discussion we have identified the following user stories:
Add book: George, the administrator of Emporium, must be able to add new books to the inventory.
Upload book cover: The administrator must be able to upload an image of the book cover. This image will be shown to customers.
List books: The administrator must be able to list all of the books that are currently available in the inventory.
View book: The administrator must be able to view the details of a book.
Edit book: The administrator must be able to edit the details of a book.
Delete book: The administrator must be able to delete books from the inventory.
We aren’t sure how we should implement the book recommendation feature George wanted, so we decide to postpone that for a later sprint (covered in Chapter 7).
When George comes back, he tells us that he must also be able to keep track of the book publishers. After a brief brainstorming session, we come up with a list of user stories related to publisher management:
Add publisher: The administrator must be able to add publishers to the system.
List publishers: The administrator must be able to view a list of all publishers in the system.
View publisher: The administrator must be able to view the details of a publisher.
Edit publisher: The administrator must be able to edit the details of a publisher.
Delete publisher: The administrator must be able to remove publishers from the system.
We will also implement these in this sprint, as we are confident that we can finish them within the schedule.