Ruby On Rails - Top 300 Questions
Ruby On Rails - Top 300 Questions
md 1/5/2022
Ans: D
13.what kind of tests are there?
a) unit, functional, and integration tests
b) it is not associated with a model
c) id, created_at, updated_at
d) it runs its validators
Ans: A
14.how do you specify a format like html or xml in routes.rb?
a) .:format (that period is a concatenation period)
b) HTTP methods (post, get, put, delete)
c) their names begin with an underscore
d) unit, functional, and integration tests
Ans: A
15.when you put something into an array, does the array keep a separate copy?
a) no. arrays just keep references to objects stored in memory.
b) the data being presented by the web page
c) it is not associated with a model
d) the request parameters table
Ans: A
16.what is scriptlet versus expression
a) it runs its validators
b) it is not associated with a model
c) Representational State Transfer
d) expression is ruby code that prints out a value in html
Ans: D
17.what does the “h” in <%=h … %> mean?
a) .:format (that period is a concatenation period)
b) h is a helper method that escapes special characters to sanitize malicious input
c) a script that alters the structure of the underlying database
d) the method within the controller to call
Ans: B
18.whatʼs the difference between model names and controller names?
a) the method within the controller to call
b) the data being presented by the web page
c) model names are singular, controller (and table) names are plural
d) in the controller: respond_to do |format| … end
Ans: C
19.what is “migration”?
3 / 18
ruby on rails - top 300 questions.md 1/5/2022
c) an object
d) underscores
Ans: B
26.where do you add the filter code?
a) rails generate migration AddPhoneToTickets phone:string
b) the data being presented by the web page
c) data from model objects AND the page template
d) right after the line introducing the class in the controller
Ans: D
27.why is it good to redirect after inserting info into the database?
a) unit, functional, and integration tests
b) a script that alters the structure of the underlying database
c) so that users canʼt accidentally resubmit information by refreshing the page
d) the data being presented by the web page
Ans: C
28.which two steps to include test.xml data to the partial “map” (via the variable “data”)…?
a) from general to specific (‘/ads/ʼ and then ‘/ads/:idʼ)
b) include test.xml to root of “public” folder and , render (:partial=>ʼmapʼ, :locals=>{:data=>ʼ/test.xmlʼ})
c) just replace the word “scaffold” with the word “model”
d) login method (that checks a username and password) and , a filter (that calls the login method when
needed)
Ans: B
29.what environments does Rails have by default?
a) development, test, production
b) render :partial
c) RAILS_ENV (RAILS_ENV=production)
d) integration test
Ans:A
30.how do you generate regular model code (not scaffolding)?
a) just replace the word “scaffold” with the word “model”
b) it is not associated with a model
c) username == “admin” && password == “some_password”
d) do |f| (where “f” can be anything)
Ans: A
31.how should you order routes?
a) just replace the word “scaffold” with the word “model”
b) from general to specific (‘/ads/ʼ and then ‘/ads/:idʼ)
c) rails generate migration AddPhoneToTickets phone:string
5 / 18
ruby on rails - top 300 questions.md 1/5/2022
38.how does rake tell which migrations have been run and which have not?
a) rails generate migration AddPhoneToTickets phone:string
b) rails records the latest timestamp of all the migrations it runs (and runs only the latest ones)
c) because they make the partial less dependent on other code
d) it can do more complex things like modifying the database structure and running tests
Ans: B
39.how does Rails choose to correct format to generate?
a) in the controller: respond_to do |format| … end
b) it is not associated with a model
c) redirect_to ” … ”
d) the data being presented by the web page
Ans: A
40.how do you express error messages in a form (do |f|)?
a) ruby make
b) f.error_messages
c) for ad in @ads
d) underscores
Ans: B
41.what are the three “magic columns”
a) id, created_at, updated_at
b) render :partial:id
c) integration test
d) rake db:migrate delete
Ans: A
42.what tag starts a form?
a) integration test
b) <%= f.text_field :name %>
c) <% form_for() %>
d) <%= yield %>
Ans: C
43.what is params[…]?
a) have the same URL of a table
b) the word “private”
c) a responder object
d) the request parameters table
Ans: D
44.what comes after “def check_logged_in” line for site “ads”?
7 / 18
ruby on rails - top 300 questions.md 1/5/2022
d) ActionPack
Ans: C
57.what scripts does the model-generator command create?
a) their names begin with an underscore
b) the model class (app/models/something.rb) and the data migration (db/migrate/…
_create_something.rb)
c) model names are singular, controller (and table) names are plural
d) rails generate migration AddPhoneToTickets phone:string
Ans: B
58.what does Embedded Ruby (ERb) process as inputs?
a) data from model objects AND the page template
b) HTTP methods (post, get, put, delete)
c) it is not associated with a model
d) their names begin with an underscore
Ans: A
59.what kind of test do you create yourself?
a) an object
b) ActionPack
c) rake db:migrate
d) integration test
Ans: D
60.what is “format” in “repond_to do |format|”?
a) underscores
b) an object
c) a responder object
d) integration test
Ans: C
61.what does REST stand for?
a) runs State test
b) the request State Transfer
c) Representational State Transfer
d) runs State Transfer
Ans: C
62.what parameters are in <% form_for() %>?
a) data from model objects AND the page template
b) form_for(@object, :url=>{:action=>ʼcreateʼ})
c) .:format (that period is a concatenation period)
d) do |f| (where “f” can be anything)
Ans: B
10 / 18
ruby on rails - top 300 questions.md 1/5/2022
63.how do you add an error (called “there was an error”) in the validate method?
a) redirect_to ” … ”
b) errors.add_to_base(“there was an error”)
c) the word “private”
d) their names begin with an underscore
Ans: B
64.how do you call a partial?
a) a web page
b) underscores
c) singular
d) render :partial
Ans: D
65.how do you run the latest migrations?
a) ruby make
b) a web page
c) rake db:migrate
d) CamelCase
Ans: C
66.whatʼs special about a search form?
a) for ad in @ads
b) it is not associated with a model
c) Representational State Transfer
d) it runs its validators
Ans: B
67.what expression do all layouts have?
a) <%= yield %>
b) <% form_for() %>
c) integration test
d) <%= f.text_field :name %>
Ans: A
68.if the table Seats is associated with the table Flights, how should you name the table column in
Seats to indicate its flight?
a) an object
b) flight_id
c) ruby make
d) #{1+1}
Ans: B
69.how would you insert “1 + 1” into a string?
11 / 18
ruby on rails - top 300 questions.md 1/5/2022
a) CamelCase
b) #{1+1}
c) singular
d) validate
Ans: B
70.what is the second uri indicate?
a) an object
b) ActionPack
c) CamelCase
d) :controller
Ans: D
71.what precedes the “check_logged_in” method in a class?
a) the request parameters table
b) the word “private”
c) <% form_for() %>
d) redirect_to ” … ”
Ans: B
72.what method name indicates to rails that it should validate before saving/updating?
a) validate
b) ActionPack
c) flight_id
d) ruby make
Ans: A
73.how do you ask for all records of the Ads table?
a) singular
b) @ads = Ad.find(:all)
c) validate
d) rake db:migrate
Ans: B
74.when data is retrieved from the database, what does Rails turn it into?
a) a responder object
b) validate
c) flight_id
d) an object
Ans: D
75.what are the main principles of REST?
a) 1. all important data is a resource, 2. every resource has a proper name (URL), 3. you can perform a
standard set of operations on resources (usually CRUD), 4. client and server talk statelessly
b) model names are singular, controller (and table) names are plural
12 / 18
ruby on rails - top 300 questions.md 1/5/2022
81.What is a Class?
a) An array uses indices and a hash uses “keys”
b) Classes are simply a convenient way to organize functions (also called methods). In
pages_controller.rb, PagesController is a Class which holds a “home” action.
c) A controller is a container for a group of (possibly dynamic) web pages.
d) This maps requests for the URL /pages/home to the home action in the Pages controller.
Ans: B
82.What kind of object is “@title” and what is special about it in Rails?
a) Itʼs a test that simulates a browser accessing our application.
b) The “erb” stands for “Embedded RuBy”. .erb files look like about.html.erb and live in the “views”
directory.They are just html files with embedded ruby in them.
c) Ruby complains if we try to evaluate an undefined local variable, but issues no such complaint for an
instance variable; instead, instance variables are nil if not defined
d) The @ indicates that this is an “instance variable”. An instance variable defined in the action (or
function) of a controller is automatically available in the view of that same name.
Ans: D
83.What does the routes.rb file do with “get pages/home”?
a) When a request is made for, say, /pages/home, the Pages controller executes the code in the “home”
action and then automatically renders the view corresponding to the action — in this case,
home.html.erb.
b) This maps requests for the URL /pages/home to the home action in the Pages controller.
c) When the order matters, use an array.
d) Itʼs a test that simulates a browser accessing our application.
Ans: B
84.Describe a “symbol” in Rails?
a) Ruby complains if we try to evaluate an undefined local variable, but issues no such complaint for an
instance variable; instead, instance variables are nil if not defined
b) Symbols look kind of like strings, but prefixed with a colon instead of surrounded by quotes. For
example, :name is a symbol. You can think of symbols as basically strings without all the extra baggage
c) An array uses indices and a hash uses “keys”
d) This is not a standard rails directory, but a directory installed by RSpec in which all test files are kept.
Ans: B
85.What is the status code for “success” when throwing a GET?
a) 300
b) 200
c) 400
d) 150
Ans: B
86.What is the command to print to the screen?
14 / 18
ruby on rails - top 300 questions.md 1/5/2022
d) This maps requests for the URL /pages/home to the home action in the Pages controller.
Ans: C
92.Whatʼs the difference between a hash and an array?
a) An array uses indices and a hash uses “keys”
b) When the order matters, use an array.
c) Itʼs a test that simulates a browser accessing our application.
d) puts (pronounced “put-ess”)
Ans: A
93.What is a controller?
a) A controller is a container for a group of (possibly dynamic) web pages.
b) An array uses indices and a hash uses “keys”
c) Itʼs a test that simulates a browser accessing our application.
d) When the order matters, use an array.
Ans: A
94.how do you define a “status” parameter (within a “tweet” parameter)?
a) code = tweet,url = /tweets/1
b) @tweet = Tweet.create(:status => params[:status])
c) params = {:tweet => {:status => “Iʼm dead” }}
d) @tweet = Tweet.create(:status => params[:tweet][:status])
Ans: D
95.how do you check the logged in userʼs id?
a) :status
b) session[:user_id]
c) t.errors
d) the attribute
Ans: B
96.letʼs say you have a method…
def get_tweet
@tweet = Tweet.find(params[:id])
end
how do you tie an action to that that only kicks in for the edit, update, and destroy methods?
a) index, show, new, edit, create, update, destroy
b) code = tweet, :method => :delete
url = /tweets/1
c) before_filter :get_tweet, :only => [:edit, :update, :destroy]
d) @tweet = Tweet.create(:status => params[:tweet][:status])
Ans: C
97.How to includes all javascript?
16 / 18
ruby on rails - top 300 questions.md 1/5/2022
18 / 18