Ruby on Rails Basics Quiz
Test your understanding of Rails fundamentals in this fast-paced, code-friendly quiz. No login needed!
Welcome to the Rails Quiz!
This quiz will test your knowledge of Ruby on Rails basics including MVC, routing, ActiveRecord, and common commands.
Select your options in the sidebar and click "Start Quiz" to begin.
Rails Help Section
rails new app_name– Create a new Rails applicationrails server– Start the development serverrails generate model Post title:string body:text– Generate a model with fieldsrails db:migrate– Run pending database migrationsrails console– Start an interactive consolerails routes– List all defined routes
Model
Handles data and business logic.
Interacts with the database.
Example: app/models/post.rb
View
Handles presentation layer.
Renders HTML templates.
Example: app/views/posts/index.html.erb
Controller
Handles incoming requests.
Coordinates between model and view.
Example: app/controllers/posts_controller.rb
Routes are defined in config/routes.rb and map URLs to controller actions.
Common Route Types:
get '/about', to: 'pages#about'- Basic routeresources :articles- RESTful routes for a resourceresources :posts do- Nested routes
resources :comments
endroot 'pages#home'- Root route
Rails Cheat Sheet
| Concept | Example | Description |
|---|---|---|
| Generate Model | rails g model Article title:string body:text |
Creates model + migration file |
| Route Definition | get '/home' => 'pages#home' |
Maps a URL to a controller action |
| ActiveRecord Save | @post.save |
Saves a new record to the database |
| Migration Command | rails db:migrate |
Applies changes to database schema |
| Show All Routes | rails routes |
Lists all available routes |
| Controller Action | def index |
Typical controller action that fetches data |
| Form Helper | <%= form_with model: @post %> |
Creates a form bound to a model |