Start of Ruby on Rails Fundamentals Quiz
1. What is Ruby on Rails?
- Ruby on Rails is a front-end library for building user interfaces with JavaScript and HTML.
- Ruby on Rails is a software tool for managing databases and optimizing queries.
- Ruby on Rails is a graphic design framework used for creating visual presentations.
- Ruby on Rails is a server-side web application framework written in the Ruby programming language, known for its convention over configuration approach and MVC pattern.
2. What is the MVC pattern in Ruby on Rails?
- The MVC pattern in Ruby on Rails separates data, presentation, and logic into Model, View, and Controller respectively.
- The MVC pattern manages database connections and query optimizations.
- The MVC pattern in Ruby on Rails only focuses on data storage solutions.
- The MVC pattern mixes data, presentation, and logic into a single layer.
3. What is the purpose of the Model in the MVC pattern?
- The Model in the MVC pattern is responsible for managing data and interacting with the database.
- The Model in the MVC pattern routes requests to the appropriate controllers.
- The Model in the MVC pattern displays user interfaces and handles user input.
- The Model in the MVC pattern handles authentication and session management.
4. What is the purpose of the View in the MVC pattern?
- The View in the MVC pattern manages the application`s logic and rules.
- The View in the MVC pattern processes user requests and controls application flow.
- The View in the MVC pattern is responsible for rendering the user interface and displaying data.
- The View in the MVC pattern handles database interactions and data storage.
5. What is the purpose of the Controller in the MVC pattern?
- The Controller in the MVC pattern manages the application’s styling and layout.
- The Controller in the MVC pattern defines the structure of the database and its relationships.
- The Controller in the MVC pattern handles user requests, retrieves data from models, and passes it to views.
- The Controller in the MVC pattern renders the data in various formats like JSON and XML.
6. What is routing in Ruby on Rails?
- Routing in Ruby on Rails directs user requests to the appropriate controller actions by defining URL patterns.
- Routing in Ruby on Rails processes front-end stylesheets and JavaScript files.
- Routing in Ruby on Rails manages database connections and migrations only.
- Routing in Ruby on Rails creates mobile applications using the Ruby language.
7. How do you define routes in Ruby on Rails?
8. What is a dynamic segment in Ruby on Rails routing?
- A configuration file in Rails.
- A placeholder for URL parameters like `:id`.
- A method for generating routes.
- A fixed part of the URL path.
9. How do you handle a request for a specific book in Ruby on Rails?
- You can manage a specific book request by using the route `/books/specific` in the routes file.
- You can handle book requests by defining a static route for `/books` in the controller without parameters.
- You can handle a request for a specific book by defining a route like `/books/:id` and accessing the `:id` parameter in the controller.
- You can handle requests by creating a route for `/books` and listing all books in the controller.
10. What is the difference between nil, false, and empty in Ruby?
- Nil is an object type, false is a string, empty means no characters.
- Nil is absence of value, false is Boolean, empty checks container elements.
- Nil is a data type, false is never true, empty is a string.
- Nil is a variable, false is a keyword, empty is an integer.
11. How do you create a simple model in Ruby on Rails?
- new ModelName(attribute1:data_type)
- create model ModelName with attribute1:data_type
- generate model ClassName attribute1:data_type
- rails generate model ModelName attribute1:data_type attribute2:data_type
12. How do you validate a model’s presence in Ruby on Rails?
- validates :attribute_name, presence: true
- validate_presence :attribute_name
- validates_presence_of :attribute_name
- validate :attribute_name, presence: true
13. What is a Rails controller?
- A Rails controller is responsible for handling user requests, retrieving data from models, and passing it to views.
- A Rails controller serves as a database management tool and stores data directly.
- A Rails controller is a user interface component that interacts directly with the end user.
- A Rails controller is a library that provides functions for client-side rendering of applications.
14. What are filters in Ruby on Rails?
- Filters in Ruby on Rails are methods that can be executed before or after controller actions to perform tasks like authentication or logging.
- Filters in Ruby on Rails are tools that generate automated tests for controller actions to ensure reliability.
- Filters in Ruby on Rails are libraries that manage database connections and queries efficiently.
- Filters in Ruby on Rails are classes that store user session data for better performance.
15. How do you create a Rails controller action to find a User by their email address and render their profile?
- “`ruby class UsersController < ApplicationController def show_user_email render json: User.where(email: params[:email]) end end ```
- “`ruby class UsersController < ApplicationController def locate_email render json: User.find_by_email(params[:email]) end end ```
- “`ruby class UsersController < ApplicationController def get_user_by_email email = params[:email] @user = User.find(email) render json: @user end end ```
- “`ruby class UsersController < ApplicationController def find_by_email render json: User.find_by(email: params[:email]) end end ```
16. What is Active Record in Ruby on Rails?
- Active Record is a library for managing user sessions in Ruby on Rails.
- Active Record is a template engine used for rendering views in Ruby on Rails.
- Active Record is a testing framework designed for automated tests in Ruby on Rails.
- Active Record is an ORM (Object-Relational Mapping) system that allows developers to interact with the database using Ruby objects.
17. What is Action Controller & Routing in Ruby on Rails?
- Action Controller & Routing executes background jobs and manages asynchronous tasks.
- Action Controller & Routing manages database connections and queries for user data.
- Action Controller & Routing handle user requests and direct them to the appropriate controller actions based on defined routes.
- Action Controller & Routing is responsible for rendering HTML views and interacting with JavaScript.
18. What is Action View & Action Helpers in Ruby on Rails?
- Action View & Action Helpers define the application routes and direct user requests to controllers.
- Action View & Action Helpers are responsible for rendering the user interface and providing helper methods for views.
- Action View & Action Helpers are used to handle background jobs and asynchronous tasks in Rails.
- Action View & Action Helpers manage database interactions and perform data validation.
19. What are advanced concepts in Ruby on Rails?
- Action Mailers, Worker Classes, and specialized features.
- Active Support, Form Helpers, and authentication methods.
- Dynamic Segments, Static Routes, and view rendering tasks.
- Model Associations, Request Handling, and session management.
20. How does Ruby on Rails support rapid application development (RAD)?
- Ruby on Rails requires extensive code writing for setup.
- Ruby on Rails minimizes coding with its convention over configuration.
- Ruby on Rails lacks support for plugins and extensions.
- Ruby on Rails primarily focuses on frontend development only.
21. What is the role of caching in Ruby on Rails?
- Caching in Ruby on Rails creates user accounts automatically when data is accessed.
- Caching in Ruby on Rails improves performance by storing frequently accessed data in memory or other storage systems.
- Caching in Ruby on Rails encrypts all user data for secure transactions.
- Caching in Ruby on Rails reduces the size of the database by deleting unused data.
22. What is middleware in Ruby on Rails?
- Middleware in Ruby on Rails are methods for executing database queries directly from the controller.
- Middleware in Ruby on Rails are modules that can be stacked to perform tasks like authentication, logging, or rate limiting.
- Middleware in Ruby on Rails are data structures used to store application settings and configurations.
- Middleware in Ruby on Rails are templates for creating new applications quickly and efficiently.
23. How do you handle errors in Ruby on Rails?
- You log all errors to a file and don`t inform the user about them.
- You ignore errors and let the application crash for debugging purposes.
- You handle errors in Ruby on Rails by using rescue blocks or raising exceptions, and then handling them in the controller or application level.
- You change the application`s code to avoid all potential errors completely.
24. What is the purpose of the `config/routes.rb` file in Ruby on Rails?
- The `config/routes.rb` file generates controller actions in Ruby on Rails.
- The `config/routes.rb` file defines the routes that map URLs to controller actions in Ruby on Rails.
- The `config/routes.rb` file manages database connections in Ruby on Rails.
- The `config/routes.rb` file handles user authentication in Ruby on Rails.
25. How do you define a root URL in Ruby on Rails?
- You define a root URL in Ruby on Rails by specifying a route that maps to the root path, typically handled by the HomeController.
- You set a root URL using environment variables specified in the `config/application.rb` file.
- You define a root URL by modifying the `index.html` file in the `public` directory.
- You create a root URL by adding a controller action that redirects users to a homepage.
26. What is the difference between static and dynamic segments in Ruby on Rails routing?
- Static segments can change, while dynamic segments are constant.
- Static segments are fixed and dynamic segments are parametric.
- Static segments do not affect routing, while dynamic segments control everything.
- Static segments are only for images, while dynamic segments handle text.
27. How do you handle a request for a list of articles in Ruby on Rails?
- You fetch a list of articles by creating a database query in the view file directly.
- You handle a request for a list of articles by defining a route like `/articles` and accessing the corresponding controller action.
- You print the list of articles in the browser using console logs in JavaScript.
- You handle the request by retrieving the articles from an external API instead of the database.
28. What is the purpose of the `params` method in Ruby on Rails?
- The `params` method compiles SQL queries for the database.
- The `params` method creates new routes in the application.
- The `params` method encrypts user passwords for security.
- The `params` method provides access to request parameters.
29. How do you validate form data in Ruby on Rails?
- You validate form data by manually checking inputs in the view.
- You validate form data by running SQL queries in the database.
- You validate form data in Ruby on Rails using Active Record validations.
- You validate form data by using JavaScript only on the client-side.
30. What is the difference between `nil` and `false` in Ruby?
- Nil and false are interchangeable in Ruby.
- Nil represents the absence of value, while false is a Boolean value.
- Nil means true, and false means none.
- Nil is a string, and false is a number.