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.

Ruby on Rails Logo

Rails Help Section

  • rails new app_name – Create a new Rails application
  • rails server – Start the development server
  • rails generate model Post title:string body:text – Generate a model with fields
  • rails db:migrate – Run pending database migrations
  • rails console – Start an interactive console
  • rails 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 route
  • resources :articles - RESTful routes for a resource
  • resources :posts do
      resources :comments
    end
    - Nested routes
  • root '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
  @posts = Post.all
end
Typical controller action that fetches data
Form Helper <%= form_with model: @post %> Creates a form bound to a model