Publisher Administration for Book Inventory Management
(Page 1 of 2 )
In this second part of a series on working with the scaffolding feature of Ruby on Rails, you'll lean how to implement a publisher administration interface for a book inventory management system. This article is excerpted from chapter three of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).
Implementing the Publisher Administration Interface
We will start by implementing the administrator interface for maintaining the list of publishers. We need a table for storing publishers, so the first thing we need to do is to update the database schema by adding the publishers table to the database schema.
Updating the Schema with the Publishers Table
As in the previous chapter, we will use ActiveRecord migrations to make the necessary modifications to the database schema. We could also use plain SQL, but migrations have the added benefit of being database-agnostic and allowing you to roll back changes.
First, create thecreate_publishersmigration file, which you will use for adding thepublisherstable to the database schema:
The new table has two columns:idandname. Note that theidcolumn is automatically added by ActiveRecord migrations, so we need to add only thenamecolumn to the migration script. We limit thename column’s length to a maximum length of 255 characters. We also specify that we don’t accept null values in thenamefield and that the name must be unique.
Following good practices, we undo all changes in thedownmethod by telling ActiveRecord to delete thepublisherstable.