The Original Model
The person.rb file has been lurking in the models directory since the application was created. You might expect it to contain a list of fields for each person, defining data types and such. Instead, it looks like Example 7-2.
Example 7-2. The foundation of all Rails models
class Person < ActiveRecord::Base end
Thatâs pretty quiet, because the connections between Rails and the database are running purely on naming conventions. The Rake migration set up the database, as Example 6-1 demonstrated, and thatâs where all the data type information went. Perhaps itâs even disturbingly quiet, as most object-oriented programming includes some specific information about object properties in the class definition that creates them.
Railsâ minimalist approach to model classes, however, lets you focus on the pieces you need to contribute to the model. Having the definitions elsewhere may mean that you sometimes have to look around to figure out what youâre working onâespecially if youâre modifying code someone else wroteâbut it also makes a clean slate truly clean.
Note
If the emptiness really bothers you, you could put the info from the migration or even
the script/generate
call into a comment here for quick
reference. Of course, if you write another migration later, your quick reference might
rapidly prove out of date.
Get Learning Rails: Live Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.