200+ TOP RUBY ON RAILS Online Quiz Questions – Exam Test

RUBY ON RAILS Online Test and Answers Pdf Download :-

These are very useful & Most Asked Questions in your certification Exam. Read all Online Mock Test Exam Question Bank for Beginners Freshers & Experienced.

1. What is bundler?
a) rails generate scaffold User name:string email:string
b) self-contained bundles of gems. Useful for versioning.
c) Edit Gemfile, then run ‘bundle install’ or just ‘bundle’.
d) Ruby Version Manager. Install and manage multiple versions of Ruby.
Answer: C

2. What is gemset?
a) self-contained bundles of gems. Useful for versioning.
b) self-contained packages of Ruby code
c) Ruby Version Manager. Install and manage multiple versions of Ruby.
d) rails generate scaffold User name:string email:string
Answer: A

3. What is gem?
a) rails generate scaffold User name:string email:string
b) self-contained packages of Ruby code
c) self-contained bundles of gems. Useful for versioning.
d) Ruby Version Manager. Install and manage multiple versions of Ruby.
Answer: B

4. what is scaffold command?
a) rails generate scaffold User name:string email:string
b) Ruby Version Manager. Install and manage multiple versions of Ruby.
c) self-contained packages of Ruby code
d) self-contained bundles of gems. Useful for versioning.
Answer: A

5. What is rake?
a) self-contained bundles of gems. Useful for versioning.
b) bundle exec rake db:migrate. Using bundle exec ensures that the rake version in our Gemfile is used.
c) rails generate scaffold User name:string email:string
d) Ruby Version Manager. Install and manage multiple versions of Ruby.
Answer: B

6. What is rvm?
a) rails generate scaffold User name:string email:string
b) Ruby Version Manager. Install and manage multiple versions of Ruby.
c) self-contained bundles of gems. Useful for versioning.
d) self-contained packages of Ruby code
Answer: B

7.how do you create a migration that adds a “phone” field to the “tickets” table?
a) unit, functional, and integration tests
b) RAILS_ENV (RAILS_ENV=production)
c) integration test
d) rails generate migration AddPhoneToTickets phone:string
Answer: D

8.Rails’ application framework is called ———-?
a) ActionPack
b) ActiveRecord
c) a web page
d) an object
Answer: A

9.how do you run a migration?
a) CamelCase
b) ruby make
c) an object
d) rake db:migrate
Answer: D

10.what does “show” refer to as the :action value?
a) the method within the controller to call
b) HTTP methods (post, get, put, delete)
c) the data being presented by the web page
d) their names begin with an underscore
Answer: A

RUBY ON RAILS Objective Questions
RUBY ON RAILS MCQs

11.how do you update?

a) update_attributes (as in @ad.update_attributes(params[:ad]))
b) unit, functional, and integration tests
c) format (that period is a concatenation period)
d) it is not associated with a model
Answer: A

12.what comes after <% form_for()… ?

a) redirect_to ” … ”

b) the request parameters table

c) <%= f.text_field :name %>
d) do |f| (where “f” can be anything)
Answer: 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
Answer: 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
Answer: 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
Answer: 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
Answer: 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
Answer: 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
Answer: C

19.what is “migration”?

a) It is a format (that period is a concatenation period)
b) a script that alters the structure of the underlying database
c) their names begin with an underscore
d) the data being presented by the web page
Answer: B

20.what steps get you from fild.erb to file.html?

a) data from model objects AND the page template
b) .erb -> Embedded Ruby -> ruby code (file.rb) -> fild.html
c) the method within the controller to call
d) the data being presented by the web page
Answer: B

21.what is the filter code that calls on the “check_logged_in” method for only the “edit” and “update” methods?

a) the data being presented by the web page
b) HTTP methods (post, get, put, delete)
c) data from model objects AND the page template
d) before_filter :check_logged_in, :only => [:edit, :update]
Answer: D

22.representation of a resource is called ————-.

a) CamelCase
b) ruby make
c) a web page
d) ActionPack
Answer: C

23.converts database records to objects is called ————-.

a) for ad in @ads
b) integration test
c) Representational State Transfer
d) an object-relational mapping library
Answer: D

24.what checks if an input is numeric?

a) integration test
b) a responder object
c) validate
d) validates_numericality_of
Answer: D

25.what is Rails’ object-relational mapping library?

a) CamelCase
b) ActiveRecord
c) an object
d) underscores
Answer: 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
Answer: 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
Answer: 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)
Answer: 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
Answer: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)
Answer: 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
d) do |f| (where “f” can be anything)
Answer: B

32.what should you write in routes.rb to give meaning to http://mebay.com/ads/3?

a) from general to specific (‘/ads/’ and then ‘/ads/:id’)
b) map.connect ‘/ads/:id’, :controller=>’ads’, :action=>’show’
c) include test.xml to root of “public” folder and ,render (:partial=>’map’, :locals=>{:data=>’/test.xml’})
d) form_for(@object, :url=>{:action=>’create’})
Answer: B

33.to add login security, which two pieces of code do you need?

a) 1.all important data is a resource2. every resource has a proper name (URL)
b) .:format (that period is a concatenation period)
c) the method within the controller to call
d) 1. login method (that checks a username and password) and 2. a filter (that calls the login method when needed)
Answer: D

34.how do partials look compared to regular erb files?

a) underscores
b) it runs its validators
c) it is not associated with a model
d) their names begin with an underscore
Answer: D

35.how does “rake” differ from “ruby”?

a) right after the line introducing the class in the controller
b) a script that alters the structure of the underlying database
c) it can do more complex things like modifying the database structure and running tests
d) expression is ruby code that prints out a value in html
Answer: C

36.why should partials generally use local variables?

a) because they make the partial less dependent on other code
b) the data being presented by the web page
c) their names begin with an underscore
d) the request parameters table
Answer: A

37.do models have singular or plural names?

a) controller
b) CamelCase
c) flight_id
d) singular
Answer: D

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
Answer: 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
Answer: 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
Answer: 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:id:delete
Answer: A

42.what tag starts a form?

a) integration test
b) <%= f.text_field :name %>
c) <% form_for() %>
d) <%= yield %>
Answer: 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
Answer: D

44.what comes after “def check_logged_in” line for site “ads”?

a) in the controller: respond_to do |format| … end
b) errors.add_to_base(“there was an error”)
c) .:format (that period is a concatenation period)
d) authenticate_or_request_with_http_basic(“Ads”) do |username, password|
Answer: D

45.what is naming convention for classes?

a) ActionPack
b) CamelCase
c) ruby make
d) a web page
Answer: B

46.to create scafolding for “thing” data, run…

a) because they make the partial less dependent on other code
b) expression is ruby code that prints out a value in html
c) just replace the word “scaffold” with the word “model”
d) rails generate scaffold thing : : Answer: D

47.what variable changes the environment?

a) RAILS_ENV (RAILS_ENV=production)
b) development, test, production
c) render :partial
d) validates_numericality_of
Answer: A

48.what is naming convention for file names ?

a) ActiveRecord
b) underscores
c) an object
d) validate
Answer: B

49.why do you only need to call “render” in the controller sometimes and not always?

a) .:format (that period is a concatenation period)
b) redirect_to ” … ”
c) errors.add_to_base(“there was an error”)
d) if you’re happy with the default template, you can omit “render”
Answer: D

50.a RESTful application uses … to define an interaction with the data.

a) a responder object
b) it is not associated with a model
c) HTTP methods (post, get, put, delete)
d) the request parameters table
Answer: C

RUBY ON RAILS Objective type Questions with Answers

51.what generates web pages from page templates?

a) underscores
b) Embedded Ruby (ERb)
c) a web page
d) render :partial
Answer: B

52.where do you edit routs?

a) :controller
b) underscores
c) ActiveRecord
d) config/routes.rb
Answer: D

53.if looping through “f” object, how do you make a text field “name”?

a) <%= yield %>
b) … have the same URL
c) <% form_for() %>
d) <%= f.text_field :name %>
Answer: D

54.what does a model object do before it saves or updates data?

a) underscores
b) it runs its validators
c) validate
d) rake db:migrate
Answer: B

55.what does “rake” mean?

a) #{1+1}
b) singular
c) ruby make
d) flight_id
Answer: C

56.how do you start a loop that reads through the array object “@ads”?

a) a web page
b) ruby make
c) for ad in @ads
d) ActionPack
Answer: 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
Answer: 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
Answer: A

59.what kind of test do you create yourself?

a) an object
b) ActionPack
c) rake db:migrate
d) integration test
Answer: D

60.what is “format” in “repond_to do |format|”?

a) underscores
b) an object
c) a responder object
d) integration test
Answer: C

61.what does REST stand for?

a) runs State test
b) the request State Transfer
c) Representational State Transfer
d) runs State Transfer
Answer: 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)
Answer: B

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
Answer: B

64.how do you call a partial?

a) a web page
b) underscores
c) singular
d) render :partial
Answer: D

65.how do you run the latest migrations?

a) ruby make
b) a web page
c) rake db:migrate
d) CamelCase
Answer: 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
Answer: B

67.what expression do all layouts have?

a) <%= yield %>
b) <% form_for() %>
c) integration test
d) <%= f.text_field :name %>
Answer: 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}
Answer: B

69.how would you insert “1 + 1” into a string?

a) CamelCase
b) #{1+1}
c) singular
d) validate
Answer: B

70.what is the second uri indicate?

a) an object
b) ActionPack
c) CamelCase
d) :controller
Answer: 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 ” … ”
Answer: 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
Answer: 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
Answer: 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
Answer: 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
c) a script that alters the structure of the underlying database
d) no. arrays just keep references to objects stored in memory.
Answer: A

76.When is it best to use an array rather than a hash?

a) An array uses indices and a hash uses “keys”
b) puts (pronounced “put-ess”)
c) Red refers to writing a failing test
d) When the order matters, use an array.
Answer: D

77.Describe the TDD cycle.

a) An array uses indices and a hash uses “keys”
b) It’s a test that simulates a browser accessing our application.
c) Red, Green, Refactor,Red refers to writing a failing test,Green refers to writing a passing test Once we have a passing test we are free to refactor the code.
d) This maps requests for the URL /pages/home to the home action in the Pages controller.
Answer: C

78.How does a local variable differ from an instance variable when empty?

a) This is not a standard rails directory, but a directory installed by RSpec in which all test files are kept.
b) 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.
c) It’s a test that simulates a browser accessing our application.
d) 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
Answer: D

79.What is a .erb file?

a) 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.
b) 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.
c) puts (pronounced “put-ess”)
d) It’s a test that simulates a browser accessing our application.
Answer: A

80.What’s the best way to describe an object in Ruby?

a) An array uses indices and a hash uses “keys”
b) It’s easier to describe what objects do, which is respond to messages. An object like a string, for example, can respond to the message length, which returns the number of characters in the string
c) This maps requests for the URL /pages/home to the home action in the Pages controller.
d) It’s a test that simulates a browser accessing our application.
Answer: B

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.
Answer: 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.
Answer: 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.
Answer: 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.
Answer: B

85.What is the status code for “success” when throwing a GET?

a) 300
b) 200
c) 400
d) 150
Answer: B

86.What is the command to print to the screen?

a) When the order matters, use an array.
b) An array uses indices and a hash uses “keys”
c) It’s a test that simulates a browser accessing our application.
d) puts (pronounced “put-ess”)
Answer: D

87.What is the main benefit that a Class gets by inheritance from ApplicationController?

a) An array uses indices and a hash uses “keys”
b) 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.
c) This maps requests for the URL /pages/home to the home action in the Pages controller.
d) When the order matters, use an array.
Answer: B

88.Name two ways to indicate a “block” in Rails

a) This maps requests for the URL /pages/home to the home action in the Pages controller.
b) The request hits the rails router which dispatches to the proper controller action. In this case, it goes to the index action in the Users controller.
c) Curly braces or do..end. It’s best to use curly braces for short one-line blocks and the do..end for mult-iline blocks.
d) When the order matters, use an array.
Answer: C

89.What is an integration test?

a) It’s a test that simulates a browser accessing our application.
b) When the order matters, use an array.
c) puts (pronounced “put-ess”)
d) An array uses indices and a hash uses “keys”
Answer: A

90.What is the most special aspect of nil?

a) This maps requests for the URL /pages/home to the home action in the Pages controller.
b) A controller is a container for a group of (possibly dynamic) web pages.
c) When the order matters, use an array.
d) Other than the object “false” itself, nil is the only object that defaults to false.
Answer: D

91.What is the /spec directory 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) This is not a standard rails directory, but a directory installed by RSpec in which all test files are kept.
d) This maps requests for the URL /pages/home to the home action in the Pages controller.
Answer: 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”)
Answer: 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.
Answer: 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])
Answer: D

95.how do you check the logged in user’s id?

a) :status
b) session[:user_id]
c) t.errors
d) the attribute
Answer: 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])
Answer: C

97.How to includes all javascript?

a) <%= stylesheet_link_tag :all %>
b) <%= javascript_include_tag :defaults %>
c) <%= csrf_meta_tag %>
d) <%= link_to … %>
Answer: B

98.what do you use to send messages to the user?

a) t.errors
b) :status
c) a flash
d) @tweet
Answer: C

99.How includes all stylesheet files?

a) <%= javascript_include_tag :defaults %>
b) <%= csrf_meta_tag %>
c) <%= link_to … %>
d) <%= stylesheet_link_tag :all %>
Answer: D

100.How do you make sure your forms don’t get hacked?

a) <%= stylesheet_link_tag :all %>
b) <%= csrf_meta_tag %>
c) <%= link_to … %>
d) tweets_path
Answer: B

RUBY ON RAILS Questions and Answers Pdf Download