A database is simply a collection of tables. Each table is stored as
rows and columns.
|| Time to prepare
||2 cups rice, 6 tablespoon butter, 1/2 cup cashew, 1 cup raisin
||1/4 cup Milk, 3/4 cup water, little sugar
The above is what I'll henceforth call a
We will be working with variations of the
Recipe table in
this introduction. Because food is yum and everything!
To begin, type the following into the console and run it.
class Recipe < ActiveRecord::Base
Let us go over the terminology a bit before diving into the deep end. In
the first line, you defined
Recipe as an ActiveRecord class.
An ActiveRecord class is a magical beast. It gives you a beautiful set of
methods to manage the data in the underlying table.
one such method (you now know what it does, don't you?)
Over the course of this chapter, I will help you appreciate enough of
ActiveRecord to be dangerous. You will be able to build software that can
help you answer the following questions:
- Give me a dish that I can prepare in 10 minutes
- I don't like spicy food. What are all the Indian dishes that doesn't
have chillies? (if they exist!)
- I have just onions and eggs in my kitchen. What can I make?
(If you find these questions interesting, there is the lovely Cucumbertown that answers these and