Recall & Review
beginner
What is the general rule for naming database tables in Rails?
Tables should be named in plural form using lowercase letters and underscores to separate words, for example,
users or order_items.Click to reveal answer
beginner
Why does Rails use plural table names by default?
Rails uses plural table names to match the convention that a table holds many records of a model, which is usually singular. For example, the
User model corresponds to the users table.Click to reveal answer
beginner
How should multiple words be combined in a Rails table name?
Use lowercase letters with underscores between words, called snake_case. For example,
order_items instead of OrderItems or orderitems.Click to reveal answer
intermediate
What happens if you name a table in singular form in Rails?
Rails may not automatically map the table to the model correctly, causing errors or requiring manual configuration to specify the table name.
Click to reveal answer
beginner
Give an example of a correct table name for a model named
InvoiceItem.The correct table name would be
invoice_items, using plural form and snake_case.Click to reveal answer
In Rails, what is the correct table name for a model named
ProductCategory?✗ Incorrect
Rails expects table names to be plural and snake_case, so
product_categories is correct.Why should Rails table names be plural?
✗ Incorrect
Tables hold many records, so plural names reflect this collection.
Which of these is NOT a recommended Rails table naming convention?
✗ Incorrect
Rails uses snake_case, not camelCase, for table names.
What problem might occur if a table is named in singular form?
✗ Incorrect
Rails expects plural table names to map models correctly; singular names can cause mapping issues.
How should you separate words in a Rails table name?
✗ Incorrect
Rails uses underscores to separate words in table names (snake_case).
Explain the Rails convention for naming database tables and why it is important.
Think about how Rails connects models and tables automatically.
You got /5 concepts.
Describe what could happen if you do not follow Rails table naming conventions.
Consider how Rails expects table names to relate to model names.
You got /4 concepts.