5.4. Analyzing the Model

Rails' models are stored in the appmodels directory of the project. The Article model is therefore defined in the file appmodelsarticle.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 configdatabase.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.

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

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