Ruby on Rails MCQs

Ruby on Rails MCQs

Our team has conducted extensive research to compile a set of Ruby on Rails MCQs. We encourage you to test your Ruby on Rails knowledge by answering these multiple-choice questions provided below.
Simply scroll down to begin!

1: What command do you run to undo the last 5 migrations

A.   rake db:rollback STEP=5

B.   database_undo

C.   rake db:drop

D.   rake db:rollback

2: A global variable has a name beginning with:

A.   $

B.   %

C.   @

D.   @@

3: What gets returned by: [1, [2, 3,[4, 5]]].flatten

A.   [1, 2, 3, 4, 5]

B.   [1, [2, 3, 4, 5]]

C.   [2, 3, [4, 5]]

D.   [1, 2, 3, [4, 5]]

E.   {1: [2, 3, [4, 5]]}

4: How can you create a new Rails project?

A.   'rails new /path/to/new/app'

B.   'rails /path/to/new/app'

C.   'rails create /path/to/new/app'

5: Which of the following will delete the key-value 1 from array: "big_data"?

A.   big_data.del(1)

B.   big_data.del[1]

C.   big_data.delete(1)

6: What is the use of $ in Ruby?

A.   $ in Ruby is treated as a class variable

B.   $ in Ruby is treated as a global variable

7: What is the use of @@ in Ruby?

A.   class variable

B.   instance variable

8: Which is NOT a default Rails environment?

A.   sandbox

B.   test

C.   development

D.   production

9: What is a Gem?

A.   A configuration item

B.   Functionality in a package

10: Which extension is default for views html templates?

A.   .erb

B.   .slim

C.   .rabl

D.   .haml

11: In the MVC pattern:

A.   MVC are the initials of the creator, Michael Vincent Clantor.

B.   mySQL is the database, vi is the text editor, and C++ is the language.

C.   models represent the data, views display the data, and controllers respond to user interactions

D.   manipulators handle data, validators ensure data integrity, and communicators transfer information between them.

12: What is the command to install Rails?

A.   gem install ruby_on_rails

B.   gem install ror

C.   gem install rails

13: What command do you run to create your database?

A.   database_create

B.   rake db:migrate

C.   rake db:create

D.   rails create

14: What command do you run to drop your database?

A.   rails destroy

B.   rake db:drop

C.   rake db:migrate

D.   database_drop

15: How would you declare an Instance Variable?

A.   @@

B.   @

16: Ruby uses:

A.   null

B.   nil

17: What command do you run to update your database?

A.   database_update

B.   rake db:migrate

C.   rails update

D.   rake db:rollback

18: Migrations...

A.   generally affect only views and sometimes controllers.

B.   can never be reversed.

C.   back up a project by copying it to another location.

D.   are considered poor programming and are not used significantly in Rails.

E.   modify a database by adding or removing columns or tables.

19: What is the preferred method of validating that the name has been set?

A.   validates :name, :presence => true

B.   save!

C.   before_save if name != nil return true end return false end

D.   validates :name => not_null

20: Which of the following will interpolate within a string with the variable named 'monster'?

A.   "/monster"

B.   "#{monster}"

C.   {monster}

D.   "{monster}"

21: What is the output of the following ? s="foo" * 2 puts s

A.   foo*2

B.   foofoo

C.   Gives an Error

D.   foo

22: What ORM does Ruby on Rails use by default?

A.   ActiveRails

B.   ActiveSupport

C.   SQL

D.   MySQL

E.   ActiveRecord

23: What is a typical file extension found in the app/controllers directory

A.   .yml

B.   .erb

C.   .rb

D.   .html.erb

24: Which of these is not a standard directory in a Rails application?

A.   db

B.   lib

C.   app

D.   All of these are standard directories

E.   config

A.   app/assets/javascripts

B.   app/javascripts

C.   assets/javascripts

D.   public/javascripts

26: Which files is used to specify any default data that should be loaded into the application's database, when it is first setup?

A.   db/default_data.rb

B.   db/migrate/inital_load.rb

C.   db/migrate/default_data.rb

D.   db/seeds.rb

27: What is the default value for a global variable (before initialization)?

A.   null

B.   nil

C.   0

D.   nul

28: is it possible to change the default port when running a rails server ?

A.   yes

B.   no

29: Which of the following prints the "Hello WORLD!" output with a new line?

A.   puts "Hello WORLD!"

B.   print "Hello WORLD!"

C.   disp( "Hello WORLD!" )

30: How do you create a new user object with the name david and save it to the database?

A. => 'david')

B.   User.create(:name => 'david')

C. => 'david')

D.   User.make(:name => 'david')

31: Which of these does NOT correctly return the version of Ruby?


B.   --version

C.   -v

32: If you want the /person url to map to your dog controller and show method, what do you add to your routes?

A.   match '/person', :to => 'dog#show'

B.   map.resources :person

C.   map.resources :dog

D.   map.resources :person => :dog

33: What is the use of the 'defined?' method?

A.   To find the value of a variable

B.   To find the memory allocated to that variable

C.   To determine if the variable is defined at the current scope

D.   To find whether it is a constant or variable

34: Which of these javascript frameworks became the default with the release of Rails 3.1?

A.   rails.js

B.   jQuery

C.   rails-script

D.   Prototype

35: What is the use of @ in Ruby?

A.   instance variable

B.   class variable

36: Imagine that you have two models: "User" and "Book", and a user can have only one book. How should the association look like in the "User" model?

A.   belongs_to :book

B.   has_many: books

C.   has_one :books

D.   has_one :book

37: What file will rails look for given the following erb: <%= render 'some_partial' %>?

A.   +some_partial.html.erb

B.   some_partial.html.erb

C.   @some_partial.html.erb

D.   partial_some_partial.html.erb

E.   _some_partial.html.erb

38: Determine the value of the variable x after the execution of the following code. x = [1,2,3] x.pop until x.empty? x.push(4) while x.empty?

A.   [1,2,3]

B.   [4]

C.   [1]

D.   [1,2,3,4]

39: If you want to append an item to an array, what is the standard method?

A.   arr.length = arr.length+1 arr[length-1] = item

B.   arr << item


D.   arr.append(item)

40: which one is class method?

A.   class A def a end end

B.   class A def self.a end end

41: Which is NOT a model validation method?

A.   validates_numericality_of

B.   validates_length_of

C.   validates_form_of

D.   validates_presence_of

E.   validates_uniqueness_of

42: What part of a migration runs during a rollback?

A.   nothing

B.   The entire migration

C.   self.down

D.   self.up

43: Which of the following is a working ruby while-loop?

A.   while i < 100 do # DO THINGS i += 1

B.   while i < 100: # DO THINGS i += 1 end

C.   while i < 100 do # DO THINGS i += 1 end

44: A module cannot be subclassed or instantiated.

A.   True

B.   False

45: Where will routes.rb file appear?

A.   app/routes.rb

B.   db/routes.rb

C.   config/routes.rb

D.   app/config/routes.rb

46: If you want the standard restful routes for your person controller, how do you add that?

A.   resources :person do member do post :short end collection do get :long end end

B.{|person| => :restful}

C.   resources :people

D.   map.person => {:get, :post, :put}

47: What is the difference between Symbol and String?

A.   symbols, belongs to the category of immutable

B.   string, belongs to the category of immutable

48: belongs_to: Represents the inverse of a has_one (or has_many) association.

A.   true

B.   false

49: What is the most elegant way to include a javascript file needed for only one page?

A.   Application.layout.Javascripts <<


C.   <%= javascript_include_tag

D.   :render => {:javascript => 'FILE NEEDED'}

50: Which is NOT a Ruby operator?

A.   ||

B.   <=

C.   &&

D.   =!

E.   !=