Complete the code to define a Rails model using convention over configuration.
class User < ApplicationRecord # Rails automatically maps this model to the [1] table end
Rails automatically maps the model User to the users table by following naming conventions.
Complete the code to create a controller action that renders the default view using Rails conventions.
class PostsController < ApplicationController def index @posts = Post.all render [1] end end
In Rails, if you omit the render call or pass nil, it renders the default view matching the action name.
Fix the error in the route definition by completing the blank with the correct Rails convention.
Rails.application.routes.draw do
resources :[1]
endRails expects resource names in routes to be lowercase and plural, so posts is correct.
Fill both blanks to define a model with a custom table name using Rails conventions.
class [1] < ApplicationRecord self.table_name = '[2]' end
self.table_name when the table name differsWhen the table name differs from the Rails convention, you set self.table_name to the actual table name, which is usually lowercase and plural.
Fill all three blanks to complete a Rails migration that creates a table following conventions.
class Create[1] < ActiveRecord::Migration[6.1] def change create_table :[2] do |t| t.string :[3] t.timestamps end end end
The migration class name is camel case and plural, the table name is lowercase plural, and the column name follows simple naming conventions.