Session 2: Rails First Pass
During this session we began examining the command line API for Rails using generators to create the models, views, and controllers for a couple objects within a simple event registration app. The scaffold generator allows the simultaneous creation of all the basic files needed for a "resource" from the migration that creates the database table to hold the records, to the model that will define the behavior attached to those records, to the controller and views that all basic CRUD operations on the data.
We are guiding the students through a small application that will track guests coming to a fundraising event and the student that sold the ticket. So we started with the Seller model with a few basic fields. Almost as soon as we first looked at the "New" form for the Guest model, the limitations of the generated scaffold code became apparent. The Guest model holds a reference to a Seller and the scaffolded view shows the default interpretation of a Seller object as a string.
We gave the team a brief overview of how actions lead to a view and a layout in order to construct a full HTML response.
We introduced associations, linking Guests with Sellers. Then we changed the form to use an HTML <select> tag present the available Sellers by email and return its database ID as the value. Finally, we created a custom method to replace the to_s method in Seller to facilitate easily changing the drop-down display from email to a first and last name.
The teams worked as pairs for the first time and were encouraged to "tap in" if they wanted control of the keyboard. We expect that this will become more natural as they begin driving the process compared to the more "learning/following" mode that we’re in right now.
Of course, there were also a number of smaller, sometimes unintentional, lessons along the way:
the power of listening (aka, do as I "say", not as I "wrote")
changing a text_field into a select for a simple range
options_from_collection_for_select
instance variables in the controller