Ruby on Rails
Models

The purpose of a Model in the MVC Architecture is to manage the behavior and the data of a certain problem domain (i.e. the data in your tables).

In Rails, each table is represented by an associated Model file. If you use Rails pluralization rules, your Model should be the singular noun form of your table name (which should be the plural form).

The role of your Model file should be methods that pertain to database (SQL) queries, validations, before and after save and update methods. Additionally any meta-methods about your data that you wish to have to provide virtual data about your table (e.g. you have a student’s grades table, you could have a meta-method that calculates a students GPA from this data, but the actual GPA value is stored no where in the database).

Related:

category: Glossary