In this post you can find Complete and recently updated Correct Question and answers of Ruby on Rails. All Answers updated regularly with new questions. Upwork Ruby on Rails test answers of 2016.
Python
PHP
CSS
android
html5
SEO
Javascript
Adobe Photoshop
Wordpress
Perl
Joomla
Twitter Bootstrap
EX4
Magento
Ruby on Rails
jQuery
Drupal
C Programming
C++
C#
SQL
Node.js
Django
CCNA
Question:* What command do you run to undo the last 5 migrations
Answer: • rake db:rollback STEP=5
Question:* How do you remove a column during a migration?
Answer: • remove_column :table_name, :column_name
Question:* Which of the following is a working ruby while-loop?
Answer: • while i < 100 do # DO THINGS i += 1 end
Question:* Which of these is NOT a default subdirectory of the app/ directory?
Answer: • environments
Question:* REST stands for...
Answer: • REpresentational State Transfer
Question:* What part of a migration runs during a rollback?
Answer: • self.down
Question:* If you want the /person url to map to your dog controller and show method, what do you add to your routes?
Answer: • match '/person', :to => 'dog#show'
Question:* What is the use of the 'defined?' method?
Answer: • To determine if the variable is defined at the current scope
Question:* What ORM does Ruby on Rails use by default?
Answer: • ActiveRecord
Question:* What is the preferred method of validating that the name has been set?
Answer: • validates :name, :presence => true
Question:* What command do you run to update your database?
Answer: • rake db:migrate
Question:* Which is NOT a default Rails environment?
Answer: • sandbox
Question:* What command do you run to create your database?
Answer: • rake db:create
Question:* Which of the following will interpolate within a string with the variable named 'monster'?
Answer: • "#{monster}"
Question:* An instance variable has a name beginning with___________.
Answer: • @
Question:* Migrations...
Answer: • modify a database by adding or removing columns or tables.
Question:* Which of these is not a standard directory in a Rails application?
Answer: • All of these are standard directories
Question:* What is the output of the following ? s="foo" * 2 puts s
Answer: • foofoo
Question:* In the MVC pattern:
Answer: • models represent the data, views display the data, and controllers respond to user interactions
Question:* What is a typical file extension found in the app/controllers directory
Answer: • .rb
Question:* What is the default value for a global variable (before initialization)?
Answer: • nil
Question:* What command do you run to drop your database?
Answer: • rake db:drop
Question:* What is the command to install Rails?
Answer: • gem install rails
Question:* Which of these statements will utilize the gem named 'mygem'?
Answer: • require 'mygem'
Question:* How can you create a new Rails project?
Answer: • 'rails new /path/to/new/app'
Question:* Which of these does NOT correctly return the version of Ruby?
Answer: • -VERSION
Question:* Which of the following prints the "Hello WORLD!" output with a new line?
Answer: • puts "Hello WORLD!"
Question:* The recommended directory in which to place your app's javascript files is:
Answer: • app/assets/javascripts
Question:* 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?
Answer: • db/seeds.rb
Question:* 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?
Answer: • [4]
Question:* Which of these javascript frameworks became the default with the release of Rails 3.1?
Answer: • jQuery
Question:* If you want to append an item to an array, what is the standard method?
Answer: • arr << item
Question:* Ruby uses:
Answer: • nil
Question:* which one is class method?
Answer: • class A def self.a end end
Question:* 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?
Answer: • has_one :book
Question:* Which is NOT a Ruby operator?
Answer: • =!
Question:* If you want the standard restful routes for your person controller, how do you add that?
Answer: • resources :people
Question:* Which of the following will delete the key-value 1 from array: "big_data"?
Answer: • big_data.delete(1)
Question:* Which is NOT a model validation method?
Answer: • validates_form_of
Question:* If you create PostsController, where will Rails look for its templates by default?
Answer: • app/views/posts
Question:* What is the most elegant way to include a javascript file needed for only one page?
Answer: • <%= javascript_include_tag "FILE NEEDED" %>
Question:* Which of the following will check the array named "big_data" for the presence of a key "icecream"?
Answer: • big_data.has_key?("icecream")
Question:* Which is NOT a reserved Ruby logic flow word?
Answer: • elseif
Question:* Where do you add named scopes?
Answer: • Models
Question:* 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)?
Answer: • rake assets:precompile
Question:* If you have posts and each post has_many comments, how do you structure your routes?
Answer: • resources :posts do resources :comments end
Question:* Where will routes.rb file appear?
Answer: • config/routes.rb
Question:* How would you check to see if an array named COLORS contains the the value 'red'?
Answer: • COLORS.include?('red')
Question:* Unit tests are used to test what part of a Rails application?
Answer: • Models
Question:* Of the following, which would create a new project without unit test?
Answer: • $ rails new example_app -T
Question:* Which is NOT an ActiveRecord query method?
Answer: • has
Question:* Which is an incorrectly defined method?
Answer: • def method_name() # method operations
Question:* What is not a RESTful controller action?
Answer: • insert
Question:* Functional tests are used to test what part of a Rails application?
Answer: • Controllers
Question:* When rendering a partial on a collection, what is the recommended method?
Answer: • <%= render :partial => 'partial_to_render', :collection => @collection %>
Question:* Which of these is not a valid form helper?
Answer: • text_box
Question:* If you want to display the price of an item, with a :time_span tag, where would you place this code?
Answer: • helper_function or view
Question:* What is the output of the following? @@x = 10 puts defined? @@x
Answer: • class variable
Question:* To randomize the order of entries in an Array, use the _______ method.
Answer: • shuffle
Question:* Which of the following is a correctly formatted multi-line comment?
Answer: • =begin COMMENT =end
Question:* Which does NOT append "nine" to the array: "big_data"?
Answer: • big_data.append("nine")
Question:* As of Rails 3 and later, where is the default location for code that does environment-specific configuration?
Answer: • /config/environments/[environment_name].rb
Question:* The session is, by default, accessible to:
Answer: • controllers and views
Question:* In the context of unit testing Rails applications, "fixture" refers to which of the following?
Answer: • Predefined data for populating the testing database
Question:* How do you create a new user object with the name david and save it to the database?
Answer: • User.create(:name => 'david')
Question:* Ruby supports single inheritance, multiple inheritance, or both?
Answer: • Single Inheritance
Question:* Ruby 1.9, what new method of building key-value pairs is supported?
Answer: • :
Question:* A class variable (not class level instance variable) has a name beginning with ___________.
Answer: • @@
Question:* Which of these is NOT a valid way of associating models?
Answer: • has_and_belongs_to
Question:* What is the output of the following? puts 'a\nb'
Answer: • a\nb
Question:* A correct example of class inheritance from "Exception" into "Bomber"
Answer: • class Bomber < Exception def initialize # Instance end end
Question:* A global variable has a name beginning with:
Answer: • $
Question:* What is the output of the following? $x = 10 puts defined? $X
Answer: • nil
Question:* What is not a proper REST verb?
Answer: • update
Question:* In a Rails migration, what's the syntax for creating a table?
Answer: • create_table :table_name
Question:* String objects are _______.
Answer: • Mutable
Question:* Which of the following controller methods is NOT properly paired with its HTTP counterpart?
Answer: • SHOW for PUT
Question:* Which is NOT an ActiveRecord migration method?
Answer: • add_key
Question:* Which of the following associations does NOT declare a many-to-many relationship?
Answer: • has_many
Question:* For your app to route the "http://myapp.com/" to the home controller, index action; what could you add to your routes.rb file?
Answer: • root :to => "home#index"
Question:* 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?
Answer: • In controller: flash[:error] = message
Question:* Which of these code blocks cannot be right?
Answer: • = form_for User do |f|
Question:* What kind of variables are Author and AUTHOR?
Answer: • constant
Question:* Which column type is NOT supported by Active Record?
Answer: • blob
Question:* How does the Asset Pipeline (Rails 3.1 +) deal with different precompiled versions of an asset?
Answer: • Append MD5 digest to filename at precompile
Question:* What is the proper way to subclass a Module?
Answer: • You cannot subclass a Module.
Question:* What is the ActionView form helper tag for <input type="text" name="foo" id="foo"/>
Answer: • <%= text_field_tag "foo" %>
Question:* If the class User has a belongs_to :role, which table has the foreign key?
Answer: • User
Question:* Which expression will not return a sum of array elements in Ruby on Rails?
Answer: • None of them. All will return the sum.
Question:* If a method is protected:
Answer: • It may be called by any instance of the defining class or its subclasses
Question:* What should be the standard table name for has_and_belongs_to_many relationship between teams and users?
Answer: • teams_users
Question:* What does Model.reset_column_information do?
Answer: • Resets all the cached information about columns.
Question:* Which is not a valid callback?
Answer: • after_delete
Question:* In The Author Model, how do you create a nested association between Authors and Blogs?
Answer: • has_many :blogs
Question:* Which HTTP method is used by default when clicking a button defined using the ActionView helper method 'button_to'?
Answer: • post
Question:* What's an equivalent way of performing the following (h is a Hash): h.each { |k,v| h.delete k if k.nil? }
Answer: • h.delete_if { |k,v| k.nil? }
Question:* 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
Answer: • All of the above
Question:* link_to('link text', url, :remote => true) does which of the following?
Answer: • Creates a link to url with HTML attribute data-remote="true"
Question:* Determine the value of the variable a, b and c after the execution of the following code. a, b, c = 1, 2, 3, 4
Answer: • a = 1 b = 2 c = 3
Question:* In development mode (config.assets.digest = false), if a file exists in app/assets/javascript/hello.js, which link will show that file ?
Answer: • localhost:3000/assets/hello.js
Question:* Counter caches can be used for:
Answer: • Caching the counts of associations to avoid unnecessary Model.count queries
Question:* If you're using the standard Rails RESTful routes, then which of the following actions map to the url, '/posts'?
Answer: • posts#create or posts#index
Question:* If you're using the standard Rails RESTful routes, then which of the following actions map to the url, '/posts'?
Answer: • posts#create or posts#index
Question:* All Ruby number objects are instances of class _____.
Answer: • Numeric
Question:* What is the output of the following ? person1 = "Tim" person2 = person1 person1[0] = 'J' puts person1 puts person2
Answer: • Jim Jim
Question:* Handling an AJAX request in controller, which of the following redirects to google?
Answer: • render js: "window.location = 'http://google.com'"
Question:* Choose the correct result p a = 1, a = 2
Answer: • 1 //line break// 2
Question:* 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
Answer: • true
Question:* 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:
Answer: • belongs_to :parent_post, :class_name => 'Post'
Question:* 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:
Answer: • In controller: flash.now[:error] = message
Question:* 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:
Answer: • flash.now[:notice] = notice_message
Question:* Which one IS NOT an application server:
Answer: • Tomahawk
Question:* Which of the following will return true?
Answer: • false.class.superclass == Object
Question:* What is the output of the following? a = (1 <=> 2) b = (1 <=> 1.0) c = (b <=> a) puts c
Answer: • 1
Question:* 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']
Answer: • 2 and 4
Question:* Which of the following are NOT Ruby keywords? 1) alias 2) yield 3) defined? 4) include?
Answer: • 4
Question:* Which of the following will return false?
Answer: • (1...5) === 5
Question:* The index_by method is...
Answer: • a Ruby on Rails method to create a Hash from an Array with keys computed by the block argument
Question:* Initialize method is always:
Answer: • private
Question:* How can you get a list of all available rails generators?
Answer: • rails generate
Question:* Which of the following is not a standard validates option?
Answer: • :unique
Question:* What is the output of following? 1==(0||1)
Answer: • false