Olete.in
Articles
Mock Tests
🧪 Ruby on Rails MCQ Quiz Hub
Ruby on Rails Multiple choice Questions Set 2
Choose a topic to test your knowledge and improve your Ruby on Rails skills
1. what are the main principles of REST?
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
model names are singular, controller (and table) names are plural
a script that alters the structure of the underlying database
no. arrays just keep references to objects stored in memory.
2. When is it best to use an array rather than a hash?
An array uses indices and a hash uses "keys"
puts (pronounced "put-ess")
Red refers to writing a failing test
When the order matters, use an array
3. .Describe the TDD cycle.
An array uses indices and a hash uses "keys"
It's a test that simulates a browser accessing our application.
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.
This maps requests for the URL /pages/home to the home action in the Pages controller.
4. How does a local variable differ from an instance variable when empty?
This is not a standard rails directory, but a directory installed by RSpec in which all test files are kept.
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.
It's a test that simulates a browser accessing our application.
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
5. What is a .erb file?
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.
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.
puts (pronounced "put-ess")
It's a test that simulates a browser accessing our application.
6. What's the best way to describe an object in Ruby?
An array uses indices and a hash uses "keys"
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 stri
This maps requests for the URL /pages/home to the home action in the Pages controller.
It's a test that simulates a browser accessing our application.
7. What is a Class?
An array uses indices and a hash uses "keys"
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.
A controller is a container for a group of (possibly dynamic) web pages.
This maps requests for the URL /pages/home to the home action in the Pages controller.
8. What kind of object is "@title" and what is special about it in Rails?
It's a test that simulates a browser accessing our application.
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.
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
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.
9. .What does the routes.rb file do with "get pages/home"?
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.
This maps requests for the URL /pages/home to the home action in the Pages controller.
When the order matters, use an array.
It's a test that simulates a browser accessing our application.
10. Describe a "symbol" in Rails?
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
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 baggag
An array uses indices and a hash uses "keys"
This is not a standard rails directory, but a directory installed by RSpec in which all test files are kept.
11. What is the status code for "success" when throwing a GET?
300
200
400
150
12. What is the command to print to the screen?
When the order matters, use an array.
An array uses indices and a hash uses "keys"
It's a test that simulates a browser accessing our application.
puts (pronounced "put-ess")
13. What is the main benefit that a Class gets by inheritance from ApplicationController?
An array uses indices and a hash uses "keys"
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
When the order matters, use an array.
This maps requests for the URL /pages/home to the home action in the Pages controller.
14. Name two ways to indicate a "block" in Rails
This maps requests for the URL /pages/home to the home action in the Pages controller.
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.
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.
When the order matters, use an array.
15. What is an integration test?
It's a test that simulates a browser accessing our application.
When the order matters, use an array.
puts (pronounced "put-ess")
An array uses indices and a hash uses "keys"
16. What is the most special aspect of nil?
This maps requests for the URL /pages/home to the home action in the Pages controller.
A controller is a container for a group of (possibly dynamic) web pages.
When the order matters, use an array.
Other than the object "false" itself, nil is the only object that defaults to false.
17. What is the /spec directory in rails?
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
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 baggag
This is not a standard rails directory, but a directory installed by RSpec in which all test files are kept.
This maps requests for the URL /pages/home to the home action in the Pages controller.
18. What's the difference between a hash and an array?
An array uses indices and a hash uses "keys"
When the order matters, use an array.
It's a test that simulates a browser accessing our application.
puts (pronounced "put-ess")
19. What is a controller?
A controller is a container for a group of (possibly dynamic) web pages.
An array uses indices and a hash uses "keys"
It's a test that simulates a browser accessing our application.
When the order matters, use an array.
20. how do you define a "status" parameter (within a "tweet" parameter)?
code = tweet,url = /tweets/1
@tweet = Tweet.create(:status => params[:status])
params = {:tweet => {:status => "I'm dead" }}
@tweet = Tweet.create(:status => params[:tweet][:status])
21. .how do you check the logged in user's id?
status
session[:user_id]
t.errors
the attribute
22. 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?
index, show, new, edit, create, update, destroy
code = tweet, :method => :delete url = /tweets/1
before_filter :get_tweet, :only => [:edit, :update, :destroy]
@tweet = Tweet.create(:status => params[:tweet][:status])
23. How to includes all javascript?
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
<%= link_to ... %>
24. what do you use to send messages to the user?
t.errors
status
a flash
@tweet
25. .how includes all stylesheet files?
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
<%= link_to ... %>
<%= stylesheet_link_tag :all %>
26. how do you make sure your forms don't get hacked?
<%= stylesheet_link_tag :all %>
<%= csrf_meta_tag %>
<%= link_to ... %>
tweets_path
27. how do you make a link to a zombie's profile with the text of a zombies name?
<%= link_to tweet.zombie.name, zombie_path(tweet.zombie) %>
<%= javascript_include_tag :defaults %>
<%= link_to ... %>
<%= stylesheet_link_tag :all %>
28. how do you do validate to ensure ":status" exists and that it's length is at least 3 long?
validates :status, :presence => true, :length => {:minimum => 3}
params = {:tweet => {:status => "I'm dead" }}
<%= stylesheet_link_tag :all %>
code = tweet, :method => :delete url = /tweets/1
29. what code generates the url "/tweets/new"? (action = new tweet form)
tweets_path
@tweet
new_tweet_path
Embedded Ruby
30. How to create multiple hashes inside "params" (like "status" within "tweet")?
params = {:tweet => {:status => "I'm dead" }}
@tweet = Tweet.create(:status => params[:status])
code = tweet, :method => :delete url = /tweets/1
@tweet = Tweet.create(:status => params[:tweet][:status])
31. .how do you make a link?
the attribute
<%= csrf_meta_tag %>
<%= link_to ... %>
<%= stylesheet_link_tag :all %>
32. what code generates the url "/tweets"?
new_tweet_path
a flash
@tweet
tweets_path
33. what do you write to indicate that a tweet from table "tweets" only belongs to one zombie? (from table "zombies")? a) class Tweet validates_presence_of :status end
class Tweet validates_presence_of :status end
class Zombie < ActiveRecord::Base has_many :tweets end
class Tweet < ActiveRecord::Base belongs_to :zombie end
class TweetsController < ApplicationController ...
34. .show errors in object "t"
@tweet
t.presence
t.status
35. what file corresponds to the "show" method
a) new_tweet_path
/app/views/tweets/show.html.erb
tweets_path
the attribute
36. what does "erb" stand for in file_name.erb?
Error ruby
Embedded Ruby
Enchanter ruby
Extract ruby
37. what is partial page templates (or partials)?
another term for hash
embedded ruby code in templates
a tag containing a piece of ruby code
fragments of pages that are stored in separate files
38. What is scriptlet?
a tag containing a piece of ruby code
an environment
another term for hash
integration test
39. ----sets the location and type of your databbase as well as a few other settings (like how long messages will be recorded)
a fixture
unit test
an action
an environment
40. how you start a form that matches a model object?
form_tag
model form
form_for
a fixture
41. how you start a form that doesn't match a model object
unit test
form_tag
a fixture
form_for
42. which web application that integrates data and services from other places on the web
a fixture
an action
form_for
mashup
43. how is authenticity token works?
where url requests come through
fragments of pages that are stored in separate files
embedded ruby code in templates
used by Rails to ensure that a request comes from a Rails-generated page
44. In Rails, a test of a model class is called ----------------.
a fixture
functional test
an action
unit test
45. In Rails, a test of an individual controller is called ------------------.
an action
functional test
integration test
unit test
46. what test that tests the whole system?
an environment
functional test
integration test
unit test
47. A form bound to a model object is called -------.
form_for
model form
an action
a fixture
48. what is called a set of test data?
an action
a fixture
form_tag
unit test
49. what is a layout?
a tag containing a piece of ruby code
the set of operations that a Rails app carries out in response to a request from a user
fragments of pages that are stored in separate files
this defines an html wrapper for all of the templates belonging to a particular model
50. What is Ruby on Rails?
Web application framework
PHP framework
Train loaded with Rubies
None of the above
51. .Who wrote Ruby on Rails?
Gudo Rossum
Yukihiro Matsumoto
David Hansson
None of these
52. .Does Ruby on Rails make app development easier?
Yes, It does
No, It doesn't
No Idea
none
53. What does DRY mean?
Don't rub yourself
Don't repeat yourself
Don't redo yourself
None of These
Submit