Ruby on Rails MCQs: This section contains multiple-choice questions on Ruby on Rails. All MCQs have the correct answers and explanations. These MCQs will help students and professionals to test their skills and to enhance their knowledge of Ruby on Rails.
List of Ruby on Rails MCQs
1. Rails is ____.
- A web application framework
- A ORM tool
- A Library of Ruby
- Rails is a web application framework.
Answer: A) A web application framework
Explanation:
Ruby on Rails (Rails) is a web application framework.
2. Rails framework runs on which of the following programming language?
- Python
- Java
- Ruby
- Perl
Answer: C) Ruby
Explanation:
Rails is a web application framework running on the Ruby programming language.
3. Which of the following, creates a new application?
- $ rails latest
- $ rails now
- $ rails new
- $ rails create
Answer: C) $ rails new
Explanation:
$ rails new, create a new application.
4. The controllers, models, views, helpers, mailers, channels, tasks, and assets for your application are all located in which of the following folder?
- Config
- Public
- App
- temp
Answer: C) App
Explanation:
The controllers, models, views, helpers, mailers, channels, tasks, and assets for your application are all located in the app folder.
5. Which of the following folder has the Rails script that launches your application as well as any additional scripts you might need to install, configure, update, or otherwise manage your application?
- Config
- Temp
- Public
- Bin
Answer: D) Bin
Explanation:
The “Bin” folder has the Rails script that launches your application as well as any additional scripts you might need to install, configure, update, or otherwise manage your application.
6. Which of the following folder contains compiled assets and static files?
- Temp
- Static
- Public
- Bin
Answer: C) Public
Explanation:
The public folder contains compiled assets and static files.
7. Which of the following folder is a place for all third-party code?
- Rakefile
- Vendor
- Static
- App
Answer: B) Vendor
Explanation:
A vendor folder is a place for all third-party codes.
8. To terminate the web server, use ____ in the terminal window where it is currently operating.
- Ctrl+Q
- Ctrl+W
- Ctrl+S
- Ctrl+C
Answer: D) Ctrl+C
Explanation:
To terminate the web server, use Ctrl+C in the terminal window where it is currently operating.
9. In the development environment, does rails require you to restart the server?
- Yes
- No
Answer: B) No
Explanation:
Rails often does not require you to restart the server when working in the development environment.
10. Which of the following links a controller action to a request?
- Pipeline
- Route
- Model
- Link
Answer: B) Route
Explanation:
A route links a controller action to a request.
11. Which of the following handles the request and prepares any relevant data for the view?
- Model
- Controller
- View
- Route
Answer: B) Controller
Explanation:
A controller action handles the request and prepares any relevant data for the view.
12. A ____ presents information in the specified format.
- View
- Modal
- Window
Answer: A) View
Explanation:
A view presents information in the specified format.
13. Views are templates that are often created using a combination of HTML and Ruby. True or false?
- True
- False
Answer: A) True
Explanation:
Views are templates that are often created using a combination of HTML and Ruby.
14. Routes are rules written in a ____.
- HTTP protocols
- Python
- TCP
- Ruby DSL (Domain-Specific Language).
Answer: D) Ruby DSL (Domain-Specific Language).
Explanation:
Routes are rules written in a Ruby DSL (Domain-Specific Language).
15. Does Rails applications use require to load application code?
- Yes
- No
Answer: B) No
Explanation:
Rails applications do not use require to load application code.
16. A ____ is a Ruby class that is used to represent data.
- View
- Param
- Model
Answer: C) Model
Explanation:
The root segment is the segment that sits at the top of the hierarchy.
17. ____ are used to change the database structure of an application.
- Migrate
- Transitions
- Migrations
Answer: C) Migrations
Explanation:
Migrations are used to change the database structure of an application.
18. In Rails applications, migrations are written in ____.
- Ruby
- Python
- Perl
- C#
Answer: A) Ruby
Explanation:
To provide database independence, migrations in Rails applications are written in Ruby.
19. Rails provides a routes method named ____ that maps all of the conventional routes for a collection of resources.
- Require
- Resources
- Options
- Maps
Answer: B) Resources
Explanation:
Rails provides a route method named resources that maps all of the conventional routes for a collection of resources.
20. We can inspect what routes are mapped by running which of the following command?
- bin/rails routes
- bin/rails routing mapped
- bin/rails mapped
- bin/rails route_mapped
Answer: A) bin/rails routes
Explanation:
We can inspect what routes are mapped by running the bin/rails routes command.
21. Which of the following statement is True?
- Statement 1: Render triggers a new request from the browser.
- Statement 2: render will render the supplied view for the current request.
Answer: B) Statement 2: render will render the supplied view for the current request.
Explanation:
Statement 2 is correct i.e., render will render the supplied view for the current request.
22. To develop our form, we’ll utilize a Rails functionality known as a ____.
- Form Generator
- Form Creator
- Form decorator
- Form builder
Answer: D) Form builder
Explanation:
To develop our form, we’ll utilize a Rails functionality known as a form builder.
23. To assist us to cope with erroneous user input, Rails has a feature called ____.
- Vitiate
- Corroborate
- Validations
- Retrospect
Answer: C) Validations
Explanation:
To assist us to cope with erroneous user input, Rails has a feature called validations.
24. ____ returns true if this object has been destroyed, otherwise returns false.
- Destroy()
- Destroy!()
- Delete!()
- Destroyed?()
Answer: D) Destroyed?()
Explanation:
destroyed?() returns true if this object has been destroyed, otherwise returns false.
25. Does the delete statement also deletes the records marked as #readonly?
- Yes
- No
Answer: A) Yes
Explanation:
Yes, the delete statement will also delete the records marked as #readonly.
26. Which of the following statement is True?
- Statement 1: redirect_to will trigger a new request from the browser.
- Statement 2: redirect_to will render the supplied view for the current request.
Answer: A) Statement 1: redirect_to will trigger a new request from the browser.
Explanation:
Statement 1 is correct i.e., redirect_to will trigger a new request from the browser.
27. There is no callback execution, and the row is simply deleted with an SQL ____ statement.
- DELETE
- DESTROY
- DELETE!
- DESTROY!
Answer: A) DELETE
Explanation:
There is no callback execution, and the row is simply deleted with an SQL DELETE statement.
28. What is the difference between destroy and delete?
- Delete runs any callbacks on the model while Destroy doesn’t.
- Destroy runs any callbacks on the model while Delete doesn’t.
Answer: B) Destroy runs any callbacks on the model while Delete doesn’t.
Explanation:
Destroy and delete differ in a certain that destroy executes any callbacks on the model while delete does not.
29. Which of the following updates a single attribute and saves the record?
- update_columns(attributes)
- update!(attributes)
- update_column(name, value)
- update_attribute(name, value)
Answer: D) update_attribute(name, value)
Explanation:
update_attribute(name, value) updates a single attribute and saves the record.
30. ____ uses an UPDATE SQL query to make changes to the attributes directly in the database and sets them in the receiver.
- update_columns(attributes)
- update!(attributes)
- update_column(name, value)
- update_attribute(name, value)
Answer: A) update_columns(attributes)
Explanation:
update columns(attributes) uses an UPDATE SQL query to make changes to the attributes directly in the database and sets them in the receiver:
31. Which of the following is the fastest way to update attributes?
- update_columns(attributes)
- update!(attributes)
- update_column(name, value)
- update_attribute(name, value)
Answer: A) update_columns(attributes)
Explanation:
update columns(attributes) is the fastest way to update attributes because it goes straight to the database.
32. Rails offers how many built-in assertions which are designed to make testing routes simpler?
- 5
- 4
- 3
- 2
Answer: C) 3
Explanation:
To make testing routes easier, Rails comes with three built-in assertions:
- assert_generates
- assert_recognizes
- assert_routing
33. Which of the following can be used with default routes or custom routes, and it claims that a specific set of options produces a specific path?
- assert_generates
- assert_recognizes
- assert_routing
Answer: A) assert_generates
Explanation:
Assert_generates can be used with default routes or custom routes, and it claims that a specific set of options produces a specific path.
34. Among assert_recognizes and assert_routing which of the following is the inverse of assert_generates?
- assert_recognizes
- assert_routing
Answer: A) assert_recognizes
Explanation:
assert_recognizes is the inverse of assert_generates.
35. Which of the following option allows you to override the named route helper names that are typically used?
- :over
- :method
- :as
- :override
Answer: C) :as
Explanation:
The :as option allows you to override the named route helper names that are typically used.
36. ____ allow the program to keep track of user-specific data while users engage with it.
- Transactions
- Sessions
- Cycles
Answer: B) Sessions
Explanation:
Sessions allow the program to keep track of user-specific data while users engage with it.
37. Which of the following assertion verifies the route in both directions: it verifies that both the path and the options are generated?
- assert_generates
- assert_recognizes
- assert_routing
Answer: C) assert_routing
Explanation:
The assert_routing assertion verifies the route in both directions: it verifies that both the path and the options are generated.
38. Cookies have a size limit of ____.
- 10KB
- 100KB
- 4KB
Answer: C) 4KB
Explanation:
Cookies have a size limit of 4 kB.
39. You can redirect any path to another path by using the ____ helper in your router.
- Divert
- Pass
- Routes
- Redirect
Answer: D) Redirect
Explanation:
You can redirect any path to another path by using the redirect helper in your router.
40. With the ____ option, you can specifically designate a controller to use for the resource.
- :routingengine
- :redirect
- :path
- :controller
Answer: D) :controller
Explanation:
With the :controller option, you can specifically designate a controller to use for the resource.
41. Cookies are stored on the ____.
- Client-side
- Server-side
Answer: A) Client-side
Explanation:
Cookies are stored on the client-side.
42. Cookies are ____ by nature.
- Permanent
- Temporary
Answer: B) Temporary
Explanation:
Cookies are temporary by nature.
43. Rails ____ cookies by default?
- Decrypt
- Encrypt
- None
Answer: B) Encrypt
Explanation:
By default, Rails encrypts cookies. Without compromising the cookie’s encryption, the client is unable to view or modify its information.
44. The ____ command combines the results of two SQL searches into a single set.
- Intersection
- Append
- Union
Answer: C) Union
Explanation:
The UNION command combines the results of two SQL searches into a single set.
45. An ____ attack involves injecting malicious code or parameters into a web application to run it within a secure environment
- Hijacking
- CSRF
- Injection
Answer: C) Injection
Explanation:
An injection attack involves injecting malicious code or parameters into a web application to run it within a secure environment.
46. To remove an attachment from a model, use the ____ command on the attachment.
- Revoke
- Remove
- Delete
- Purge
Answer: D) Purge
Explanation:
To remove an attachment from a model, use the purge command on the attachment.
47. Active Storage supports how many ways to serve files?
- 2
- 3
- 4
- 5
Answer: A) 2
Explanation:
Active Storage supports two ways to serve files: redirecting and proxying.
48. All Active Storage controllers are ____ by default.
- Privately accessible
- Publicly accessible
Answer: B) Publicly accessible
Explanation:
All Active Storage controllers are publicly accessible by default.
49. Rails offers how many standard spots to place initialization code?
- 2
- 3
- 4
- 5
Answer: D) 5
Explanation:
Rails offers four standard spots to place initialization code:
- config/application.rb
- Environment-specific configuration files
- Initializers
- After-initializers
50. Which method is used to specify a filter that is executed before to a controller action?
- before_router
- before_action
- before_engine
- before_component
Answer: B) before_action
Explanation:
before_action method is used to specify a filter that is executed before a controller action.
51. Instance variable in Ruby begins with ____.
- @@
- @
- &
- __
Answer: B) @
Explanation:
The instance Variable in Ruby begins with @ symbol.
52. Which of the following inheritance does Ruby support?
- Multilevel
- Multiple
- Hierarchical
- Single
- All of the above
Answer: D) Single
Explanation:
Ruby only supports single inheritance.
53. CSRF stands for ____.
- Combine system request forgery
- Crucial site render forgery
- Cross-site render forgery
- Cross-site request forgery
Answer: D) Cross-site request forgery
Explanation:
CSRF stands for Cross-Site Request Forgery.
54. ____ is a sort of attack when the attacker sends a form to a separate website on your behalf that might result in harm or the disclosure of sensitive data.
- Crypto-jacking
- CSRF
- DDOS
- Injection
Answer: B) CSRF
Explanation:
CSRF is a sort of attack when the attacker sends a form to a separate website on your behalf that might result in harm or the disclosure of sensitive data.
55. Class variable in Ruby begins with ____.
- @@
- @
- &
- __
Answer: A) @@
Explanation:
Class Variable in Ruby begins with @@ symbol.
56. Is Ruby an object-oriented programming language?
- Yes
- No
Answer: A) Yes
Explanation:
Ruby is an object-oriented programming language inspired by PERL and Python.
57. Global variable in Ruby begins with ____.
- @@
- $$
- &
- $
Answer: D) $
Explanation:
Global Variable in Ruby begins with $ symbol.
58. ____ are modules that offer techniques that your view can use right away.
- Component
- Assertions
- Helpers
Answer: C) Helpers
Explanation:
Helpers are modules that offer techniques that your view can use right away.
59. Which of the following access modifiers are not used in Ruby?
- Public
- Private
- Protected
- None
Answer: D) None
Explanation:
Ruby has three access modifiers: public, protected, and private.
60. In Ruby, the scaffolding is done automatically?
- True
- False
Answer: A) True
Explanation:
In Ruby, the scaffolding is done automatically.
61. Which of the following type of variable is available in the Ruby class?
- Local Variables
- Global Variables
- Class Variables
- Instance Variables
- All of the above
Answer: E) All of the above
Explanation:
Types of variables available in Ruby Class are,
- Local Variables
- Global Variables
- Class Variables
- Instance Variables
62. When a model object changes, ____ are in charge of terminating or expiring caches.
- Injectors
- Janitors
- Sweepers
Answer: C) Sweepers
Explanation:
When a model object changes, sweepers are in charge of terminating or expiring caches.
63. Plugins are installed ____.
- In the application folder
- On a machine
Answer: A) In the application folder
Explanation:
The plugin is also ruby code, it is installed in the application folder and only available for that specific application.
64. Ruby ____ is a technique for adding a string to a literal.
- Interpolation
- Substitution
- Injection
Answer: A) Interpolation
Explanation:
Ruby interpolation is a technique for adding a string to a literal.
65. What is a gem?
- A gem is a just ruby code that is installed on a machine
- A gem is a just ruby code that is installed in the application folder
Answer: A) A gem is a just ruby code that is installed on a machine
Explanation:
A gem is a just ruby code that is installed on a machine and accessible to any Ruby programs running on that computer.