Do you know that? 73% like freelancing because there is no commute / can work from anywhere next

Contact Email: teammmrem@yahoo.com

<< All Upwork (oDesk) and Elance Tests << Elance test answers << IT & Programming category

Test answers for Ruby on Rails 2016

(122, CL) Last updated: January 23
Elance • IT & Programming
Questions and answers are regularly updated. Answered and not answered tests questions.

This helps getting job: Hundreds of (cover letter examples , interview questions , profile samples ) • Earn on Upwork (oDesk)
Job assistance: jobs popularityfreelance rates

Popular test answers: HTML, .Net, CSS, English, SEO, Photoshop, iOS, Java, Android, Ruby, Python, JavaScript

See all 6 tests answers updated

Find Upwork (oDesk) and Elance test answers on this website:



Collapse | Expand

122 Answered Test Questions:

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

Answers:

• rake db:rollback STEP=5

• rake db:drop

• database_undo

• rake db:rollback

2. How do you remove a column during a migration?

Answers:

• drop_column :column_name

• remove_column :column_name

• remove_column => :column_name

• remove_column :table_name, :column_name

3. Which of the following is a working ruby while-loop?

Answers:

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

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

• while i < 100 do # DO THINGS i += 1

4. Which of these is NOT a default subdirectory of the app/ directory?

Answers:

• models

• environments

• controllers

• helpers

• All of these are subdirectories of the app/ directory

5. REST stands for...

Answers:

• Related Entity Simple Technology

• REpresentational State Transfer

• REquired STate

• Request Example Synchronized Test

6. What part of a migration runs during a rollback?

Answers:

• self.up

• The entire migration

• self.down

• nothing

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

Answers:

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

• map.resources :person

• map.resources :dog

• map.resources :person => :dog

8. What is the use of the 'defined?' method?

Answers:

• To find whether it is a constant or variable

• To find the memory allocated to that variable

• To find the value of a variable

• To determine if the variable is defined at the current scope

9. What ORM does Ruby on Rails use by default?

Answers:

• SQL

• ActiveRecord

• ActiveSupport

• ActiveRails

• MySQL

10. What is the preferred method of validating that the name has been set?

Answers:

• before_save if name != nil return true end return false end

• save!

• validates :name => not_null

• validates :name, :presence => true

11. What command do you run to update your database?

Answers:

• rake db:rollback

• database_update

• rake db:migrate

• rails update

12. Which is NOT a default Rails environment?

Answers:

• development

• sandbox

• production

• test

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

Answers:

• rake db:create

• database_create

• rails create

• rake db:migrate

14. Which of the following will interpolate within a string with the variable named 'monster'?

Answers:

• "#{monster}"

• "{monster}"

• {monster}

• "/monster"

15. An instance variable has a name beginning with___________.

Answers:

• @@

• %

• $

• @

16. Migrations...

Answers:

• generally affect only views and sometimes controllers.

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

• can never be reversed.

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

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

17. Which of these is not a standard directory in a Rails application?

Answers:

• db

• app

• All of these are standard directories

• config

• lib

18. What is the output of the following ? s="foo" * 2 puts s

Answers:

• Gives an Error

• foo*2

• foo

• foofoo

19. In the MVC pattern:

Answers:

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

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

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

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

20. What is a typical file extension found in the app/controllers directory

Answers:

• .yml

• .html.erb

• .erb

• .rb

21. What is the default value for a global variable (before initialization)?

Answers:

• nul

• nil

• null

• 0

22. What command do you run to drop your database?

Answers:

• database_drop

• rails destroy

• rake db:migrate

• rake db:drop

23. What is the command to install Rails?

Answers:

• gem install ror

• gem install rails

• gem install ruby_on_rails

24. Which of these statements will utilize the gem named 'mygem'?

Answers:

• require 'mygem'

• instantiate 'mygem'

• sudo 'mygem'

• import 'mygem'

• utilize 'mygem'

25. How can you create a new Rails project?

Answers:

• 'rails create /path/to/new/app'

• 'rails new /path/to/new/app'

• 'rails /path/to/new/app'

26. Which of these does NOT correctly return the version of Ruby?

Answers:

• -VERSION

• -v

• --version

27. Which of the following prints the "Hello WORLD!" output with a new line?

Answers:

• disp( "Hello WORLD!" )

• print "Hello WORLD!"

• puts "Hello WORLD!"

28. The recommended directory in which to place your app's javascript files is:

Answers:

• app/javascripts

• assets/javascripts

• app/assets/javascripts

• public/javascripts

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

Answers:

• db/default_data.rb

• db/migrate/inital_load.rb

• db/migrate/default_data.rb

• db/seeds.rb

30. 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?

Answers:

• [1,2,3]

• [4]

• [1]

• [1,2,3,4]

31. Which of these javascript frameworks became the default with the release of Rails 3.1?

Answers:

• rails-script

• jQuery

• Prototype

• rails.js

32. If you want to append an item to an array, what is the standard method?

Answers:

• arr.append(item)

• arr << item

• arr.map(item.clone)

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

33. Ruby uses:

Answers:

• nil

• null

34. which one is class method?

Answers:

• class A def a end end

• class A def self.a end end

35. 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?

Answers:

• has_one :books

• has_many: books

• has_one :book

• belongs_to :book

36. Which is NOT a Ruby operator?

Answers:

• !=

• <=

• =!

• ||

• &&

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

Answers:

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

• resources :people

• response.map{|person| => :restful}

• resources :person do member do post :short end collection do get :long end end

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

Answers:

• big_data.delete(1)

• big_data.del[1]

• big_data.del(1)

39. Which is NOT a model validation method?

Answers:

• validates_presence_of

• validates_form_of

• validates_uniqueness_of

• validates_numericality_of

• validates_length_of

40. If you create PostsController, where will Rails look for its templates by default?

Answers:

• app/views

• app/templates/posts

• app/views/posts

• app/views/templates

• app/templates

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

Answers:

• <script type='text/javascript' src='FILE NEEDED'></script>

• :render => {:javascript => 'FILE NEEDED'}

• <%= javascript_include_tag "FILE NEEDED" %>

• Application.layout.Javascripts << "FILE NEEDED"

42. Which of the following will check the array named "big_data" for the presence of a key "icecream"?

Answers:

• big_data.has_key["icecream"]

• big_data.has_key?["icecream"]

• big_data.has_key?("icecream")

43. Which is NOT a reserved Ruby logic flow word?

Answers:

• break

• else

• elseif

• elsif

• if

44. Where do you add named scopes?

Answers:

• Views

• Migrations

• Models

• ApplicationController

45. Which command, when run, will compile all assets in the 'app/assets' directory and copy compiled versions to a configured target directory ('public/assets' by default)?

Answers:

• rake assets:compileanddeploy

• rake assets:precompile

• rake assets:compile

• rake assets:deploy

46. If you have posts and each post has_many comments, how do you structure your routes?

Answers:

• resources :posts, :comments

• resources :posts do resources :comments end

• resources :comments do resources :posts end

47. Where will routes.rb file appear?

Answers:

• app/routes.rb

• app/config/routes.rb

• db/routes.rb

• config/routes.rb

48. How would you check to see if an array named COLORS contains the the value 'red'?

Answers:

• COLORS.has?('red')

• COLORS.include?('red')

• COLORS.contains?('red')

• 'red'.includedIn?(COLORS)

49. Unit tests are used to test what part of a Rails application?

Answers:

• Helpers

• Views

• Controllers

• Models

50. Of the following, which would create a new project without unit test?

Answers:

• $ rails new example_app --database=postgresql

• $ rails new example_app -T

• $ rails new example_app -O

• $ rails new example_app --skip-bundle

51. Which is NOT an ActiveRecord query method?

Answers:

• order

• where

• select

• has

• group

52. Which is an incorrectly defined method?

Answers:

• def method_name() # method operations end

• def method_name() # method operations

• def method_name # method operations end

53. What is not a RESTful controller action?

Answers:

• edit

• index

• insert

• update

54. Functional tests are used to test what part of a Rails application?

Answers:

• Models

• Javascript

• Views

• Controllers

55. When rendering a partial on a collection, what is the recommended method?

Answers:

• <%= render :partial => 'partial_to_render', :source => @collection.each %>

• <%= render :partial => 'partial_to_render', :collection => @collection %>

• <% @collection.each do |item| %> <%= render :partial => 'partial_to_render', item %> <% end %>

56. Which of these is not a valid form helper?

Answers:

• password_field

• text_field

• hidden_field

• text_box

• radio_button

57. If you want to display the price of an item, with a :time_span tag, where would you place this code?

Answers:

• helper_function or view

• view or model

• model or migration

• migration or helper_function

58. What is the output of the following? @@x = 10 puts defined? @@x

Answers:

• global-variable

• class variable

• instance-variable

• local-variable

59. To randomize the order of entries in an Array, use the _______ method.

Answers:

• sort

• scramble

• sample

• random

• shuffle

60. Which of the following is a correctly formatted multi-line comment?

Answers:

• /# COMMENT #/

• / COMMENT

• ### COMMENT ###

• =begin COMMENT =end

• """ COMMENT """"

61. Which does NOT append "nine" to the array: "big_data"?

Answers:

• big_data.append("nine")

• big_data.push("nine")

• big_data << "nine"

62. As of Rails 3 and later, where is the default location for code that does environment-specific configuration?

Answers:

• /config/application.rb

• /config/environments.rb

• /config/environment.rb

• /config/locales/[environment_name].rb

• /config/environments/[environment_name].rb

63. The session is, by default, accessible to:

Answers:

• models and views

• controllers only

• controllers and views

• models only

• controllers and models

64. In the context of unit testing Rails applications, "fixture" refers to which of the following?

Answers:

• Fields which remain fixed across all records in the testing database

• The result expected from a passing unit test

• The required action to get a unit test to pass

• Predefined data for populating the testing database

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

Answers:

• User.new(:name => 'david')

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

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

• User.build(:name => 'david')

66. Ruby supports single inheritance, multiple inheritance, or both?

Answers:

• It does not support inheritance

• Both

• Multiple Inheritance

• Single Inheritance

67. Ruby 1.9, what new method of building key-value pairs is supported?

Answers:

• =>

• :=

• :

68. A class variable (not class level instance variable)  has a name beginning with     ___________.

Answers:

• %

• $

• @

• @@

69. Which of these is NOT a valid way of associating models?

Answers:

• has_and_belongs_to_many

• has_and_belongs_to

• belongs_to

• has_one

• has_many

70. What is the output of the following?  puts 'a\nb'

Answers:

• anb

• a\nb

• a b

• a/b

71. A correct example of class inheritance from "Exception" into "Bomber"

Answers:

• class Bomber << Exception def initialize # Instance end end

• class Bomber < Exception def initialize # Instance end end

• class Bomber(Exception) def initialize # Instance end end

72. A global variable has a name beginning with:

Answers:

• @

• %

• $

• @@

73. What is the output of the following? $x = 10 puts defined? $X

Answers:

• class variable

• instance-variable

• nil

• local-variable

74. What is not a proper REST verb?

Answers:

• update

• delete

• get

• post

• put

75. In a Rails migration, what's the syntax for creating a table?

Answers:

• sudo gem install make_table

• create_table => :table_name

• create_table :table_name

• rake db:create TableName

76. String objects are _______.

Answers:

• Neither of these

• Immutable

• Mutable

77. Which of the following controller methods is NOT properly paired with its HTTP counterpart?

Answers:

• SHOW for PUT

• DESTROY for DELETE

• None of these

• CREATE for POST

• INDEX for GET

78. Which is NOT an ActiveRecord migration method?

Answers:

• add_column

• add_key

• drop_table

• add_index

• change_table

79. Which of the following associations does NOT declare a many-to-many relationship?

Answers:

• has_and_belongs_to_many

• has_many :through

• has_many

80. For your app to route the "http://myapp.com/" to the home controller, index action; what could you add to your routes.rb file?

Answers:

• root => "home#index"

• root :to => "home#index"

• root => "home/index"

• root_to "home", "index"

81. When you've got a form, and when the user submits invalid data, you redirect back to the edit form. If you want to show a general error message (not tied to validation errors) to the user, you'd do which of the following?

Answers:

• In controller: flash.error = message

• In controller: flash.now.error = message

• In controller: flash.now[:error] = message

• At the top of page: <%= message %>

• In controller: flash[:error] = message

82. Which of these code blocks cannot be right?

Answers:

• = form_for :user do |f|

• = form_for User do |f|

• = form_for current_user do |f|

• = form_for @user do |f|

• = simple_form_for @user do |f|

83. What kind of variables are Author and AUTHOR?

Answers:

• constant

• class

• local

• global

84. Which column type is NOT supported by Active Record?

Answers:

• float

• decimal

• binary

• datetime

• blob

85. How does the Asset Pipeline (Rails 3.1 +) deal with different precompiled versions of an asset?

Answers:

• Append datetime to filename at precompile

• Append random 32 character string at precompile

• Append MD5 digest to filename at precompile

• Append version number to filename at precompile

86. What is the proper way to subclass a Module?

Answers:

• module SuperModule < SubModule; end

• You cannot subclass a Module.

• module SuperModule << SubModule; end

• module SuperModule << SubModule;

• module SuperModule < SubModule;

87. What is the ActionView form helper tag for <input type="text" name="foo" id="foo"/>

Answers:

• <%= text_field_tag "foo" %>

• <%= text_tag "foo" %>

• <%= input_tag :type=>"text", :name=>"foo", :id=>"foo" %>

• <%= text_input "foo" %>

88. If the class User has a belongs_to :role, which table has the foreign key?

Answers:

• Role

• Neither

• Both

• User

89. Which expression will not return a sum of array elements in Ruby on Rails?

Answers:

• array.inject { |sum, e| sum + e }

• array.sum

• None of them. All will return the sum.

• array.inject(:+)

• sum = 0; array.each { |e| sum += e }; sum

90. If a method is protected:

Answers:

• It may be called only by the instance of defining class

• It may not be called by any instances.

• It may be called only by the instance of its subclasses

• It may be called by any instance of the defining class or its subclasses

91. What should be the standard table name for has_and_belongs_to_many relationship between teams and users?

Answers:

• teams_and_users

• team_user

• team_users

• users_and_teams

• teams_users

92. What does Model.reset_column_information do?

Answers:

• Resets the column names of the table.

• Resets the existing records with the provided value.

• Resets the index of the corresponding table.

• Resets the data type of the column.

• Resets all the cached information about columns.

93. Which is not a valid callback?

Answers:

• before_destroy

• after_validation

• before_update

• after_delete

• after_save

94. In The Author Model, how do you create a nested association between Authors and Blogs?

Answers:

• :blog has_many :author

• has_many :blogs, :through => :author

• :author has_many :blog

• has_many :blog

• has_many :blogs

95. Which HTTP method is used by default when clicking a button defined using the ActionView helper method 'button_to'?

Answers:

• get

• delete

• post

• put

96. What's an equivalent way of performing the following (h is a Hash): h.each { |k,v| h.delete k if k.nil? }

Answers:

• h.keys.compact!

• The original will raise a NoMethodError

• h.delete_if { |k,v| k.nil? }

• h.compact!

• The original will result in a warning: multiple values for a block parameter

97. Which of the following are valid objects of class Integer or one of its subclasses?  1) -123 2)  0xFF 3)  123_456_789  4)  123456789123456789123456789123456789

Answers:

• 4

• All of the above

• 1 and 4

• 1

98. link_to('link text', url, :remote => true) does which of the following?

Answers:

• Creates a link to url with an "onclick" HTML attribute that results in an AJAX call when user clicks

• Creates an HTML link that will be inactive if the user's browser has javascript disabled

• Creates an HTML link with 'link text' as text and url as the href

• Creates a link to url with HTML attribute data-remote="true"

99. Determine the value of the variable a, b and c after the execution of the following code. a, b, c = 1, 2, 3, 4

Answers:

• a = [1, 2] b = 3 c = 4

• a = 1 b = 2 c = [3, 4]

• a = 1 b = [2,3] c = 4

• a = 1 b = 2 c = 3

100. In development mode (config.assets.digest = false), if a file exists in app/assets/javascript/hello.js, which link will show that file ?

Answers:

• localhost:3000/assets/javascript/hello.js

• localhost:3000/assets/hello.js

• localhost:3000/assets/application.js

• localhost:3000/hello.js

101. Counter caches can be used for:

Answers:

• Flushing caches when models are modified

• Saving space in the database by consolidating count query results

• Caching the counts of associations to avoid unnecessary Model.count queries

• Caching the results of Model.count queries to bypass hitting the database

• Caching arbitrary query results (often of the form Model.count)

102. If you're using the standard Rails RESTful routes, then which of the following actions map to the url, '/posts'?

Answers:

• posts#all or posts#index

• posts#destroy_all or posts#index

• posts#update or posts#index or posts#edit

• posts#show or posts#index or posts#create

• posts#create or posts#index

103. If you're using the standard Rails RESTful routes, then which of the following actions map to the url, '/posts'?

Answers:

• posts#all or posts#index

• posts#destroy_all or posts#index

• posts#update or posts#index or posts#edit

• posts#show or posts#index or posts#create

• posts#create or posts#index

104. All Ruby number objects are instances of class _____.

Answers:

• Fixnum

• Numeric

• Bignum

• BigDecimal

105. What is the output of the following ? person1 = "Tim" person2 = person1 person1[0] = 'J' puts person1 puts person2

Answers:

• Tim Tim

• Jim Jim

• Jim Tim

• Tim Jim

106. Handling an AJAX request in controller, which of the following redirects to google?

Answers:

• redirect_to 'http://google.com'

• redirect_javascript "http://google.com"

• render js: "window.location = 'http://google.com'"

• All of these

107. Choose the correct result p a = 1, a = 2

Answers:

• 1

• 2

• 1 //line break// 2

• [1,2]

• "12"

108. Given the following code:  ;    module Wheeled; end ;    class Vehicle; end ;    class Car < Vehicle ;      include Wheeled ;    end ;     What is the value of this expression:          Car.new.kind_of? Wheeled

Answers:

• nil

• Vehicle

• no value (raises ArgumentError)

• true

• false

109. To establish an association from a Post model to another Post model (say if one post is in response to another and there is a parent_post_id column on the posts table), you would add the following to the Post model:

Answers:

• has_one :parent_post_id, :class_name => 'Post'

• has_many :parent_posts, :foreign_key => 'parent_post_id'

• belongs_to :post, :foreign_key => 'parent_post_id'

• belongs_to :parent_post, :class_name => 'Post'

• has_one :parent_post, :class_name => 'Post'

110. You've got a form, and when the user submits invalid data, you simply show them an error page (no redirect). In the controller, to show the general error on the rendered page, you would add:

Answers:

• At the top of page: <%= message %>

• In controller: flash.now[:error] = message

• In controller: flash.error = message

• In controller: flash[:error] = message

• In controller: flash.now.error = message

111. If your controller gets an action that it will render a template for, and you need to add a flash notice to the page, you'd use:

Answers:

• flash.now.notice(notice_message)

• flash.notice(notice_message)

• flash.now[:notice] = notice_message

• flash = notice_message

• flash[:notice] = notice_message

112. Which one IS NOT an application server:

Answers:

• Tomahawk

• Thin

• Unicorn

• Ebb

• Rainbows

113. Which of the following will return true?

Answers:

• true.is_a? Boolean

• all of these

• false.class.superclass == Object

• true.class == Boolean

114. What is the output of the following? a = (1 <=> 2)  b = (1 <=> 1.0)  c = (b <=> a)  puts c

Answers:

• FALSE

• 1

• 2

• 0

115. We have given: str = 'abcdef' Which of the following will return the string 'def'? 1) str[0,-3] 2) str[-3,3] 3) str[4,3] 4) str['def']

Answers:

• 2 and 4

• 2

• 1

• 1 and 2

116. Which of the following are NOT Ruby keywords? 1) alias 2) yield  3) defined?  4) include?

Answers:

• 4

• 3

• 1 and 2

• 2 and 3

117. Which of the following will return false?

Answers:

• All of these

• (1...5) === 5

• (1..10) != 1

• 123 == 123.0

118. The index_by method is...

Answers:

• not a method in standard Ruby on Rails

• a Ruby on Rails method to create a Hash from an Array with keys computed by the block argument

• an ActiveRecord helper method for fetching results in groups of size specified by the argument

• an ActiveRecord migration helper method for creating database table indexes

• a standard ruby method on Array for creating a Hash index from an Array with keys computed by the block argument

119. Initialize method is always:

Answers:

• protected

• default

• public

• private

120. How can you get a list of all available rails generators?

Answers:

• rails generate --tasks

• rails g --list

• rails generate

• rake generate --tasks

• rake generate

121. Which of the following is not a standard validates option?

Answers:

• :unique

• :exclusion

• :confirmation

• :presence

122. What is the output of following?  1==(0||1)

Answers:

• true

• false