Ruby in Web Development explores the powerful frameworks Ruby on Rails and Sinatra, the MVC architecture, and how to build web applications using Ruby. These 30 MCQs test your knowledge of Ruby’s web development concepts.
1. Introduction to Ruby on Rails and Sinatra
What is Ruby on Rails primarily used for?
A) Data manipulation
B) Web application development
C) Game development
D) Desktop applications
Which of the following is a key feature of Ruby on Rails?
A) Convention over configuration
B) Focus on desktop applications
C) Mobile application development
D) Hardware programming
What is Sinatra in the context of Ruby?
A) A library for data visualization
B) A framework for building web applications
C) A tool for managing databases
D) A package for Ruby data structures
What does the acronym “MVC” stand for in web development?
A) Model, View, Controller
B) Module, View, Controller
C) Model, Variable, Class
D) Module, Variable, Class
Which of the following is true about Ruby on Rails?
A) It is a lightweight framework with minimal features
B) It is designed for full-stack web development
C) It is only used for front-end development
D) It focuses on back-end architecture only
What is one key difference between Ruby on Rails and Sinatra?
A) Rails is a full-stack web framework, while Sinatra is minimalistic
B) Sinatra is for mobile apps, while Rails is for web apps
C) Sinatra requires more configuration than Rails
D) Rails is used for database management, while Sinatra is not
Which of the following is not a feature of Ruby on Rails?
A) Active Record for database management
B) RESTful routing
C) Convention over configuration
D) Direct access to hardware interfaces
What does Sinatra provide to developers?
A) Full-stack web application development tools
B) A minimalistic web framework for small projects
C) Predefined front-end templates
D) Advanced database management tools
What is the primary purpose of Ruby on Rails’ “convention over configuration” philosophy?
A) To reduce the amount of coding required by using common conventions
B) To make the application flexible to use
C) To focus primarily on database handling
D) To allow developers to work with various programming languages
Which of the following is a characteristic of Sinatra that differentiates it from Rails?
A) It has a built-in ORM (Object-Relational Mapping)
B) It is more suitable for large-scale applications
C) It focuses on simplicity and small applications
D) It uses a strict convention over configuration model
2. Understanding MVC Architecture
What is the primary purpose of the Model in the MVC architecture?
A) It handles the user interface
B) It manages the data and business logic
C) It manages the database connections
D) It handles the routing of requests
In the MVC pattern, what does the View do?
A) Manages data
B) Defines application logic
C) Displays the user interface
D) Handles database queries
In MVC, which component is responsible for receiving and handling user input?
A) View
B) Controller
C) Model
D) Router
What is the responsibility of the Controller in MVC architecture?
A) To render HTML pages
B) To manage data flow between Model and View
C) To manage the database
D) To display the user interface
What does “Separation of Concerns” refer to in the MVC architecture?
A) Combining business logic with user interface
B) Managing different parts of an application in isolated layers
C) Making the Model the most complex layer
D) Allowing multiple views for the same model
Which of the following best describes the relationship between the Model, View, and Controller in MVC?
A) The Controller directly modifies the View
B) The View sends requests directly to the Model
C) The Controller acts as an intermediary between the Model and View
D) The Model and View communicate directly without a Controller
In Ruby on Rails, where are the routes configured to direct incoming requests to the appropriate Controller actions?
A) config/database.yml
B) config/routes.rb
C) app/models/
D) app/views/
How does MVC architecture support easier testing of web applications?
A) By ensuring that each component (Model, View, Controller) can be tested independently
B) By providing a complete test framework out-of-the-box
C) By automatically generating test cases for every controller
D) By eliminating the need for manual testing
What does the View in the MVC architecture communicate with?
A) The database
B) The user input
C) The Controller for business logic
D) The router to manage requests
In Ruby on Rails, which directory contains the Controller files?
A) app/models/
B) app/controllers/
C) app/views/
D) app/helpers/
3. Building a Simple Web Application
What is the first step in building a web application using Ruby on Rails?
A) Define the views
B) Set up the database schema
C) Generate the application skeleton with rails new
D) Write the routes
Which command is used to generate a new controller in Ruby on Rails?
A) rails generate model
B) rails generate controller
C) rails generate view
D) rails generate route
How does Rails handle database migrations?
A) By manually editing the database
B) By using SQL scripts
C) By generating migration files and using rake db:migrate
D) By using an ORM tool directly without migrations
What is the purpose of a model in a Ruby on Rails web application?
A) To display data to the user
B) To handle database interactions and data validation
C) To define routes for the application
D) To create views and controllers automatically
In a Ruby on Rails web application, what does the rails server command do?
A) It runs the application’s database migration
B) It starts the web server to run the application locally
C) It compiles the JavaScript assets
D) It initializes the front-end framework
Which of the following best describes the role of a “view” in a Ruby on Rails web application?
A) To manage application logic and data validation
B) To handle the database schema
C) To display the HTML content to the user
D) To communicate directly with the database
In Sinatra, what method is used to define routes?
A) get
B) def
C) routes
D) render
How do you define a route to handle HTTP GET requests in Sinatra?
A) get '/path'
B) post '/path'
C) route '/path'
D) send '/path'
Which file does Ruby on Rails use to configure the routes for the application?
A) routes.rb
B) routes.yaml
C) routes.json
D) routes.config
In Ruby on Rails, which method would you use to generate a new model?
A) rails generate controller
B) rails generate migration
C) rails generate model
D) rails generate route
Answers
Qno
Answer
1
B) Web application development
2
A) Convention over configuration
3
B) A framework for building web applications
4
A) Model, View, Controller
5
B) It is designed for full-stack web development
6
A) Rails is a full-stack web framework, while Sinatra is minimalistic
7
D) Direct access to hardware interfaces
8
B) A minimalistic web framework for small projects
9
A) To reduce the amount of coding required by using common conventions
10
C) It focuses on simplicity and small applications
11
B) It manages the data and business logic
12
C) Displays the user interface
13
B) Controller
14
B) To manage data flow between Model and View
15
B) Managing different parts of an application in isolated layers
16
C) The Controller acts as an intermediary between the Model and View
17
B) config/routes.rb
18
A) By ensuring that each component (Model, View, Controller) can be tested independently
19
C) The Controller for business logic
20
B) app/controllers/
21
C) Generate the application skeleton with rails new
22
B) rails generate controller
23
C) By generating migration files and using rake db:migrate
24
B) To handle database interactions and data validation
25
B) It starts the web server to run the application locally