Olete.in
Articles
Mock Tests
π§ͺ Ruby on Rails MCQ Quiz Hub
Ruby on Rails Multiple choice Questions Set 1
Choose a topic to test your knowledge and improve your Ruby on Rails skills
1. What is bundler?
rails generate scaffold User name:string email:string
self-contained bundles of gems. Useful for versioning.
Edit Gemfile, then run 'bundle install' or just 'bundle'.
Ruby Version Manager. Install and manage multiple versions of Ruby.
2. What is gemset?
self-contained bundles of gems. Useful for versioning.
self-contained packages of Ruby code
Ruby Version Manager. Install and manage multiple versions of Ruby.
rails generate scaffold User name:string email:string
3. What is gem?
rails generate scaffold User name:string email:string
self-contained packages of Ruby code
self-contained bundles of gems. Useful for versioning.
Ruby Version Manager. Install and manage multiple versions of Ruby.
4. what is scaffold command?
rails generate scaffold User name:string email:string
Ruby Version Manager. Install and manage multiple versions of Ruby.
self-contained packages of Ruby code
self-contained bundles of gems. Useful for versioning.
5. What is rake?
self-contained bundles of gems. Useful for versioning.
bundle exec rake db:migrate. Using bundle exec ensures that the rake version in our Gemfile is used.
rails generate scaffold User name:string email:string
Ruby Version Manager. Install and manage multiple versions of Ruby.
6. how do you create a migration that adds a "phone" field to the "tickets" table?
unit, functional, and integration tests
RAILS_ENV (RAILS_ENV=production)
integration test
rails generate migration AddPhoneToTickets phone:string
7. What is rvm?
rails generate scaffold User name:string email:string
Ruby Version Manager. Install and manage multiple versions of Ruby.
self-contained bundles of gems. Useful for versioning.
self-contained packages of Ruby code
8. Rails' application framework is called ----------?
ActionPack
ActiveRecord
a web page
an object
9. how do you run a migration?
CamelCase
ruby make
an object
rake db:migrate
10. what does "show" refer to as the :action value?
the method within the controller to call
HTTP methods (post, get, put, delete)
the data being presented by the web page
their names begin with an underscore
11. how do you update?
update_attributes (as in @ad.update_attributes(params[:ad]))
unit, functional, and integration tests
format (that period is a concatenation period)
it is not associated with a model
12. what comes after <% form_for()... ?
redirect_to &quot; ... &quot;
the request parameters table
&lt;%= f.text_field :name %&gt;
do |f| (where &quot;f&quot; can be anything)
13. what kind of tests are there?
unit, functional, and integration tests
it is not associated with a model
id, created_at, updated_at
it runs its validators
14. how do you specify a format like html or xml in routes.rb?
format (that period is a concatenation period)
HTTP methods (post, get, put, delete)
their names begin with an underscore
unit, functional, and integration tests
15. when you put something into an array, does the array keep a separate copy?
no. arrays just keep references to objects stored in memory.
the data being presented by the web page
it is not associated with a model
the request parameters table
16. what is scriptlet versus expression
it runs its validators
it is not associated with a model
Representational State Transfer
expression is ruby code that prints out a value in html
17. what does the "h" in <%=h ... %> mean?
:format (that period is a concatenation period)
h is a helper method that escapes special characters to sanitize malicious input
a script that alters the structure of the underlying database
the method within the controller to call
18. .what's the difference between model names and controller names?
the method within the controller to call
the data being presented by the web page
model names are singular, controller (and table) names are plural d)
in the controller: respond_to do |format| ... end
19. what is "migration"?
It is a format (that period is a concatenation period)
a script that alters the structure of the underlying database
their names begin with an underscore
the data being presented by the web page
20. what steps get you from fild.erb to file.html?
data from model objects AND the page template
erb -&gt; Embedded Ruby -&gt; ruby code (file.rb) -&gt; fild.html
the method within the controller to call
the data being presented by the web page
21. what is the filter code that calls on the "check_logged_in" method for only the "edit" and "update" methods?
the data being presented by the web page
HTTP methods (post, get, put, delete)
data from model objects AND the page template
before_filter :check_logged_in, :only =&gt; [:edit, :update]
22. representation of a resource is called -------------.
CamelCase
ruby make
a web page
ActionPack
23. converts database records to objects is called -------------.
for ad in @ads
integration test
Representational State Transfer
an object-relational mapping library
24. what checks if an input is numeric?
integration test
Fa responder object
validate
validates_numericality_of
25. what is Rails' object-relational mapping library?
CamelCase
ActiveRecord
an object
underscores
26. what is Rails' object-relational mapping library?
CamelCase
ActiveRecord
an object
underscores
27. where do you add the filter code?
rails generate migration AddPhoneToTickets phone:string
the data being presented by the web page
data from model objects AND the page template
right after the line introducing the class in the controller
28. why is it good to redirect after inserting info into the database?
unit, functional, and integration tests
a script that alters the structure of the underlying database
so that users can&#039;t accidentally resubmit information by refreshing the page
the data being presented by the web page
29. which two steps to include test.xml data to the partial "map" (via the variable "data")...?
from general to specific (&#039;/ads/&#039; and then &#039;/ads/:id&#039;)
include test.xml to root of &quot;public&quot; folder and , render (:partial=&gt;&#039;map&#039;, :locals=&gt;{:data=&gt;&#039;/test.xml&#039;})
just replace the word &quot;scaffold&quot; with the word &quot;model&quot;
login method (that checks a username and password) and , a filter (that calls the login method when needed)
30. what environments does Rails have by default?
development, test, production
render :partial
RAILS_ENV (RAILS_ENV=production)
integration test
31. how do you generate regular model code (not scaffolding)?
just replace the word &quot;scaffold&quot; with the word &quot;model&quot;
it is not associated with a model
username == &quot;admin&quot; &amp;&amp; password == &quot;some_password&quot;
do |f| (where &quot;f&quot; can be anything)
32. how should you order routes?
just replace the word &quot;scaffold&quot; with the word &quot;model&quot;
from general to specific (&#039;/ads/&#039; and then &#039;/ads/:id&#039;)
rails generate migration AddPhoneToTickets phone:string
do |f| (where &quot;f&quot; can be anything)
33. what should you write in routes.rb to give meaning to http://mebay.com/ads/3?
from general to specific (&#039;/ads/&#039; and then &#039;/ads/:id&#039;)
map.connect &#039;/ads/:id&#039;, :controller=&gt;&#039;ads&#039;, :action=&gt;&#039;show&#039;
include test.xml to root of &quot;public&quot; folder and ,render (:partial=&gt;&#039;map&#039;, :locals=&gt;{:data=&gt;&#039;/test.xml&#039;})
form_for(@object, :url=&gt;{:action=&gt;&#039;create&#039;})
34. to add login security, which two pieces of code do you need?
1.all important data is a resource2. every resource has a proper name (URL)
:format (that period is a concatenation period)
the method within the controller to call
1. login method (that checks a username and password) and 2. a filter (that calls the login method when needed)
35. how do partials look compared to regular erb files?
underscores
it runs its validators
it is not associated with a model
their names begin with an underscore
36. how does "rake" differ from "ruby"?
right after the line introducing the class in the controller
a script that alters the structure of the underlying database
it can do more complex things like modifying the database structure and running tests
expression is ruby code that prints out a value in html
37. .why should partials generally use local variables?
because they make the partial less dependent on other code
the data being presented by the web page
their names begin with an underscore
the request parameters table
38. do models have singular or plural names?
controller
CamelCase
flight_id
singular
39. how does rake tell which migrations have been run and which have not?
rails generate migration AddPhoneToTickets phone:string
rails records the latest timestamp of all the migrations it runs (and runs only the latest ones)
because they make the partial less dependent on other code
it can do more complex things like modifying the database structure and running tests
40. how does Rails choose to correct format to generate?
in the controller: respond_to do |format| ... end
it is not associated with a model
redirect_to &quot; ... &quot;
the data being presented by the web page
41. how do you express error messages in a form (do |f|)?
ruby make
f.error_messages
for ad in @ads
underscores
42. .what are the three "magic columns"
id, created_at, updated_at
render :partial:id
integration test
rake db:migrate:id:delete
43. what tag starts a form?
integration test
&lt;%= f.text_field :name %&gt;
&lt;% form_for() %&gt;
&lt;%= yield %&gt;
44. what is params[...]?
have the same URL of a table b)
the word &quot;private&quot;
a responder object
the request parameters table
45. what comes after "def check_logged_in" line for site "ads"?
in the controller: respond_to do |format| ... end
errors.add_to_base(&quot;there was an error&quot;)
format (that period is a concatenation period)
authenticate_or_request_with_http_basic(&quot;Ads&quot;) do |username, password|
46. what is naming convention for classes?
ActionPack
CamelCase
ruby make
a web page
47. to create scafolding for "thing" data, run...
because they make the partial less dependent on other code
expression is ruby code that prints out a value in html
just replace the word &quot;scaffold&quot; with the word &quot;model&quot;
rails generate scaffold thing &lt;column name 1&gt;:&lt;column type1&gt; &lt;column name 2&gt;:&lt;column type2&gt;
48. what variable changes the environment?
RAILS_ENV (RAILS_ENV=production)
development, test, production
render :partial d)
validates_numericality_of
49. what is naming convention for file names ?
ActiveRecord
underscores
an object
validate
50. why do you only need to call "render" in the controller sometimes and not always?
.:format (that period is a concatenation period)
redirect_to &quot; ... &quot;
errors.add_to_base(&quot;there was an error&quot;)
if you&#039;re happy with the default template, you can omit &quot;render&quot;
51. a RESTful application uses ... to define an interaction with the data.
a responder object
it is not associated with a model
HTTP methods (post, get, put, delete) d)
the request parameters table
52. what generates web pages from page templates?
underscores
Embedded Ruby (ERb)
a web page
render :partial
53. where do you edit routs?
controller
underscores
ActiveRecord
config/routes.rb
54. .if looping through βfβ object, how do you make a text field βnameβ?
&lt;%= yield %&gt;
β¦ have the same URL
&lt;% form_for() %&gt;
&lt;%= f.text_field :name %&gt;
55. what does a model object do before it saves or updates data?
underscores
it runs its validators
validate
rake db:migrate
56. .what does "rake" mean?
#{1+1}
singular
ruby make
flight_id
57. .how do you start a loop that reads through the array object "@ads"?
a web page
ruby make
for ad in @ads
ActionPack
58. what scripts does the model-generator command create?
their names begin with an underscore
the model class (app/models/something.rb) and the data migration (db/migrate/..._create_something.rb)
model names are singular, controller (and table) names are plural
rails generate migration AddPhoneToTickets phone:string
59. what does Embedded Ruby (ERb) process as inputs?
data from model objects AND the page template
HTTP methods (post, get, put, delete)
it is not associated with a model
their names begin with an underscore
60. what kind of test do you create yourself?
an object
ActionPack
rake db:migrate
integration test
61. what is "format" in "repond_to do |format|"?
underscores
an object
a responder object
integration test
62. Ruby on Rails Multiple choice Questions
runs State test
the request State Transfer
Representational State Transfer
runs State Transfer
63. what parameters are in <% form_for() %>?
data from model objects AND the page template
form_for(@object, :url=&gt;{:action=&gt;&#039;create&#039;})
:format (that period is a concatenation period)
do |f| (where &quot;f&quot; can be anything)
64. how do you add an error (called "there was an error") in the validate method?
redirect_to &quot; ... &quot;
errors.add_to_base(&quot;there was an error&quot;)
the word &quot;private&quot;
their names begin with an underscore
65. how do you call a partial?
a web page
underscores
singular
render :partial
66. how do you run the latest migrations?
ruby make
a web page
rake db:migrate
CamelCase
67. what's special about a search form?
for ad in @ads
it is not associated with a model
Representational State Transfer
it runs its validators
68. what expression do all layouts have?
&lt;%= yield %&gt;
&lt;% form_for() %&gt;
integration test
&lt;%= f.text_field :name %&gt;
69. if the table Seats is associated with the table Flights, how should you name the table column in Seats to indicate its flight?
an object
flight_id
ruby make
#{1+1}
70. how would you insert "1 + 1" into a string?
CamelCase
#{1+1}
singular
validate
71. what is the second uri indicate?
an object
ActionPack
CamelCase
controller
72. what precedes the "check_logged_in" method in a class?
the request parameters table
the word &quot;private&quot;
&lt;% form_for() %&gt;
redirect_to &quot; ... &quot;
73. what method name indicates to rails that it should validate before saving/updating?
validate
ActionPack
flight_id
ruby make
74. how do you ask for all records of the Ads table?
singular
@ads = Ad.find(:all)
validate
rake db:migrate
75. .when data is retrieved from the database, what does Rails turn it into?
a responder object
validate
flight_id
an object
Submit