Dear Readers, Welcome to Ruby on Rails Objective Questions have been designed specially to get you acquainted with the nature of questions you may encounter during your Job interview for the subject of Ruby on Rails. These Objective type Ruby on Rails Questions are very important for campus placement test and job interviews. As per my experience good interviewers hardly plan to ask any particular question during your Job interview and these model questions are asked in the online technical test and interview of many IT companies.
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.
Ans: c
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
Ans: a
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.
Ans: b
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.
Ans: a
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.
Ans: b
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
Ans: b
a) unit, functional, and integration tests
b) RAILS_ENV (RAILS_ENV=production)
c) integration test
d) rails generate migration AddPhoneToTickets phone:string
Ans: d
a) ActionPack
b) ActiveRecord
c) a web page
d) an object
Ans: a
a) CamelCase
b) ruby make
c) an object
d) rake db:migrate
Ans: d
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
Ans: a
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
Ans: a
a) redirect_to " ... "
b) the request parameters table
c) <%= f.text_field :name %>
d) do |f| (where "f" can be anything)
Ans: d
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
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
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
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
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
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
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
Ans: b
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
Ans: b
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]
Ans: d
a) CamelCase
b) ruby make
c) a web page
d) ActionPack
Ans: c
a) for ad in @ads
b) integration test
c) Representational State Transfer
d) an object-relational mapping library
Ans: d
a) integration test
b) a responder object
c) validate
d) validates_numericality_of
Ans: d
a) CamelCase
b) ActiveRecord
c) an object
d) underscores
Ans: b
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
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
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
a) development, test, production
b) render :partial
c) RAILS_ENV (RAILS_ENV=production)
d) integration test
Ans: a
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
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)
Ans: b
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'})
Ans: b
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)
Ans: d
a) underscores
b) it runs its validators
c) it is not associated with a model
d) their names begin with an underscore
Ans: d
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
Ans: c
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
Ans: a
a) controller
b) CamelCase
c) flight_id
d) singular
Ans: d
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
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
a) ruby make
b) f.error_messages
c) for ad in @ads
d) underscores
Ans: b
a) id, created_at, updated_at
b) render :partial:id
c) integration test
d) rake db:migrate:id:delete
Ans: a
a) integration test
b) <%= f.text_field :name %>
c) <% form_for() %>
d) <%= yield %>
Ans: c
a) have the same URL of a table
b) the word "private"
c) a responder object
d) the request parameters table
Ans: d
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|
Ans: d
a) ActionPack
b) CamelCase
c) ruby make
d) a web page
Ans: b
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 <column name 1>:<column type1> <column name 2>:<column type2>
Ans: d
a) RAILS_ENV (RAILS_ENV=production)
b) development, test, production
c) render :partial
d) validates_numericality_of
Ans: a
a) ActiveRecord
b) underscores
c) an object
d) validate
Ans: b
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"
Ans: d
a) a responder object
b) it is not associated with a model
c) HTTP methods (post, get, put, delete)
d) the request parameters table
Ans: c
a) underscores
b) Embedded Ruby (ERb)
c) a web page
d) render :partial
Ans: b
a) :controller
b) underscores
c) ActiveRecord
d) config/routes.rb
Ans: d
a) <%= yield %>
b) … have the same URL
c) <% form_for() %>
d) <%= f.text_field :name %>
Ans: d
a) underscores
b) it runs its validators
c) validate
d) rake db:migrate
Ans: b
a) #{1+1}
b) singular
c) ruby make
d) flight_id
Ans: c
a) a web page
b) ruby make
c) for ad in @ads
d) ActionPack
Ans: c
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
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
a) an object
b) ActionPack
c) rake db:migrate
d) integration test
Ans: d
a) underscores
b) an object
c) a responder object
d) integration test
Ans: c
a) runs State test
b) the request State Transfer
c) Representational State Transfer
d) runs State Transfer
Ans: c
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
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
a) a web page
b) underscores
c) singular
d) render :partial
Ans: d
a) ruby make
b) a web page
c) rake db:migrate
d) CamelCase
Ans: c
a) for ad in @ads
b) it is not associated with a model
c) Representational State Transfer
d) it runs its validators
Ans: b
a) <%= yield %>
b) <% form_for() %>
c) integration test
d) <%= f.text_field :name %>
Ans: a
a) an object
b) flight_id
c) ruby make
d) #{1+1}
Ans: b
a) CamelCase
b) #{1+1}
c) singular
d) validate
Ans: b
a) an object
b) ActionPack
c) CamelCase
d) :controller
Ans: d
a) the request parameters table
b) the word "private"
c) <% form_for() %>
d) redirect_to " ... "
Ans: b
a) validate
b) ActionPack
c) flight_id
d) ruby make
Ans: a
a) singular
b) @ads = Ad.find(:all)
c) validate
d) rake db:migrate
Ans: b
a) a responder object
b) validate
c) flight_id
d) an object
Ans: d
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.
Ans: a
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.
Ans: d
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.
Ans: c
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
Ans: d
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.
Ans: a
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.
Ans: b
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
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
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
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
a) 300
b) 200
c) 400
d) 150
Ans: b
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")
Ans: d
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.
Ans: b
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.
Ans: c
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"
Ans: a
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.
Ans: d
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.
Ans: c
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
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
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
a) :status
b) session[:user_id]
c) t.errors
d) the attribute
Ans: b
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
a) <%= stylesheet_link_tag :all %>
b) <%= javascript_include_tag :defaults %>
c) <%= csrf_meta_tag %>
d) <%= link_to ... %>
Ans: b
a) t.errors
b) :status
c) a flash
d) @tweet
Ans: c
a) <%= javascript_include_tag :defaults %>
b) <%= csrf_meta_tag %>
c) <%= link_to ... %>
d) <%= stylesheet_link_tag :all %>
Ans: d
a) <%= stylesheet_link_tag :all %>
b) <%= csrf_meta_tag %>
c) <%= link_to ... %>
d) tweets_path
Ans: b
a) <%= link_to tweet.zombie.name, zombie_path(tweet.zombie) %>
b) <%= javascript_include_tag :defaults %>
c) <%= link_to ... %>
d) <%= stylesheet_link_tag :all %>
Ans: a
a) validates :status, :presence => true, :length => {:minimum => 3}
b) params = {:tweet => {:status => "I'm dead" }}
c) <%= stylesheet_link_tag :all %>
d) code = tweet, :method => :delete
url = /tweets/1
Ans: a
a) tweets_path
b) @tweet
c) new_tweet_path
d) Embedded Ruby
Ans: c
a) params = {:tweet => {:status => "I'm dead" }}
b) @tweet = Tweet.create(:status => params[:status])
c) code = tweet, :method => :delete
url = /tweets/1
d) @tweet = Tweet.create(:status => params[:tweet][:status])
Ans: a
a) the attribute
b) <%= csrf_meta_tag %>
c) <%= link_to ... %>
d) <%= stylesheet_link_tag :all %>
Ans: c
a) new_tweet_path
b) a flash
c) @tweet
d) tweets_path
Ans: d
a) @tweet = Tweet.create(:status => params[:tweet][:status])
b) @tweet = Tweet.create(:status => params[:status])
c) class Tweet
validates_presence_of :status
end
d) def show
@tweet = Tweet.find(1)
render :action => 'status'
end
Ans: d
a) class Tweet
validates_presence_of :status
end
b) class Zombie < ActiveRecord::Base
has_many :tweets
end
c) class Tweet < ActiveRecord::Base
belongs_to :zombie
end
d) class TweetsController < ApplicationController
...
end
Ans: c
a) @tweet
b) t.presence
c) t.errors
d) t.status
Ans: c
a) new_tweet_path
b) /app/views/tweets/show.html.erb
c) tweets_path
d) the attribute
Ans: b
a.Error ruby
b.Embedded Ruby
C.Enchanter ruby
d.Extract ruby
Ans: b
a) another term for hash
b) embedded ruby code in templates
c) a tag containing a piece of ruby code
d) fragments of pages that are stored in separate files
Ans: d
a) a tag containing a piece of ruby code
b) an environment
c) another term for hash
d) integration test
Ans: a
a) a fixture
b) unit test
c) an action
d) an environment
Ans: d
a) form_tag
b) model form
c) form_for
d) a fixture
Ans: c
a) unit test
b) form_tag
c) a fixture
d) form_for
Ans: b
a) a fixture
b) an action
c) form_for
d) mashup
Ans: d
a) where url requests come through
b) fragments of pages that are stored in separate files
c) embedded ruby code in templates
d) used by Rails to ensure that a request comes from a Rails-generated page
Ans: d
a) a fixture
b) functional test
c) an action
d) unit test
Ans: d
a) an action
b) functional test
c) integration test
d) unit test
Ans: b
a) an environment
b) functional test
c) integration test
d) unit test
Ans: c
a) form_for
b) model form
c) an action
d) a fixture
Ans: b
a) an action
b) a fixture
c) form_tag
d) unit test
Ans: b
a) a tag containing a piece of ruby code
b) the set of operations that a Rails app carries out in response to a request from a user
c) fragments of pages that are stored in separate files
d) this defines an html wrapper for all of the templates belonging to a particular model
Ans: d
a) Web application framework
b) PHP framework
c) Train loaded with Rubies
Ans: a
a) Gudo Rossum
b) Yukihiro Matsumoto
c) David Hansson
Ans: c
a) Yes, It does
b) No, It doesn't
c) No Idea
Ans: a
a) Don't rub yourself
b) Don't repeat yourself
c) Don't redo yourself
Ans: b