Skip to Content
Ruby on Rails® for Microsoft Developers
book

Ruby on Rails® for Microsoft Developers

by Antonio Cangiano
April 2009
Intermediate to advanced content levelIntermediate to advanced
479 pages
12h 55m
English
Wrox
Content preview from Ruby on Rails® for Microsoft Developers

5.4. Analyzing the Model

Rails' models are stored in the app\models directory of the project. The Article model is therefore defined in the file app\models\article.rb. This is the code contained within it:

class Article < ActiveRecord::Base
end

That's it. At this stage the model is just a class definition. The class Article inherits from ActiveRecord::Base and this is sufficient enough to obtain a fully functional model that maps an articles table in the current database.

The database in use is always (by default) the one specified in config\database.yml for the current environment mode.

Please pay attention to singulars and plurals in Rails. The model should be singular and automatically map to a plural table name. Rails is smart enough to understand that the model Mouse maps to the table mice and not (sic) mouses. The mapping for very uncommon irregular plurals may not always be correct, but you can customize the inflection rules and also set the table name manually through the set_table_name method, as explained in Chapter 7.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ruby on Rails™ 3 Tutorial: Learn Rails™ by Example

Ruby on Rails™ 3 Tutorial: Learn Rails™ by Example

Michael Hartl

Publisher Resources

ISBN: 9780470374955Purchase book