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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset