R4RIN
Articles
Java 8
MCQS
Ruby on Rails MCQ Quiz Hub
Ruby on Rails Multiple choice Questions Set 3
Choose a topic to test your knowledge and improve your Ruby on Rails skills
1. What command do you run to undo the last 5 migrations
rake db:rollback STEP=5
database_undo
rake db:drop
rake db:rollback
2. A global variable has a name beginning with:
$
%
@
@@
3. What gets returned by: [1, [2, 3,[4, 5]]].flatten
[1, 2, 3, 4, 5]
[1, [2, 3, 4, 5]]
[2, 3, [4, 5]
] [1, 2, 3, [4, 5]]
4. How can you create a new Rails project?
'rails new /path/to/new/app'
'rails /path/to/new/app'
'rails create /path/to/new/app'
None of the above
5. Which of the following will delete the key-value 1 from array: "big_data"
big_data.del(1)
big_data.del[1]
big_data.delete(1)
None of these
6. What is the use of $ in Ruby?
$ in Ruby is treated as a class variable
$ in Ruby is treated as a global variable
both (a) and (b)
None of the above
7. Which code sample will skip running the login_required "before" filter on the get_posts controller action?
Before_action :login_required, skip: [:get_posts]
Skip_before_action :login_required, except: [:get_posts]
Skip_before_action :login_required, only: [:get_posts]
Skip_action before: :login_required, only: [:get_posts
8. Which is NOT a default Rails environment?
sandbox
test
development
production
9. What is a Gem?
A configuration item
Functionality in a package
both (a) and (b)
None of the above
10. Which extension is default for views html templates?
.erb . ..
slim
rabl
haml
11. In the MVC pattern:
MVC are the initials of the creator, Michael Vincent Clantor.
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.
12. What is the command to install Rails?
gem install ruby_on_rails
gem install ror
gem install rails
None of the above
13. What command do you run to create your database?
database_create
rake db:migrate
rake db:create
rails create
14. What command do you run to drop your database?
rails destroy
rake db:drop
rake db:migrate
database_drop
15. How would you declare an Instance Variable?
@@
@
both (a) and (b)
None of these
16. Ruby uses:
null
nil
both (a) and (b)
None of these
17. What command do you run to update your database?
database_update
rake db:migrate
rails update
rake db:rollback
18. Migrations...
generally affect only views and sometimes controllers.
can never be reversed.
back up a project by copying it to another location.
modify a database by adding or removing columns or tables.
19. What is the preferred method of validating that the name has been set?
validates :name, :presence => true
save!
before_save if name != nil return true end return false end
validates :name => not_null
20. Which of the following will interpolate within a string with the variable named 'monster'?
"/monster"
"#{monster}"
{monster}
"{monster}"
21. What is the output of the following ? s="foo" * 2 puts s
foo*2
foofoo
Gives an Error
foo
22. What ORM does Ruby on Rails use by default?
ActiveRails
ActiveSupport
SQL
ActiveRecord
23. What is a typical file extension found in the app/controllers directory
.yml . .
erb
.rb
html.
24. Which of these is not a standard directory in a Rails application?
db
lib
app
All of these are standard directories
25. The recommended directory in which to place your app's javascript files is:
app/assets/javascripts
app/javascripts
assets/javascripts
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?
db/default_data.rb
db/migrate/inital_load.rb
db/migrate/default_data.rb
db/seeds.rb
27. What is the default value for a global variable (before initialization)?
null
nil
0
nul
28. Which of the following prints the "Hello WORLD!" output with a new line?
puts "Hello WORLD!"
print "Hello WORLD!"
disp( "Hello WORLD!" )
None of the above
29. How do you create a new user object with the name david and save it to the database?
User.build(:name => 'david')
User.create(:name => 'david')
User.new(:name => 'david')
User.make(:name => 'david')
30. Which of these does NOT correctly return the version of Ruby?
-VERSION
--version
-v
None of the above
31. If you want the /person url to map to your dog controller and show method, what do you add to your routes?
match '/person', :to => 'dog#show'
map.resources :person
map.resources :dog
map.resources :person => :dog
32. What is the use of the 'defined?' method?
To find the value of a variable
To find the memory allocated to that variable
To determine if the variable is defined at the current scope
To find whether it is a constant or variable
33. Which of these javascript frameworks became the default with the release of Rails 3.1?
rails.js
jQuery
rails-script
Prototype
34. When Ruby methods add an exclamation point at the end of their name (such as sort!), what does it typically indicate?
The method executes using
Any ending line return will be omitted from the result.
The method will ignore exceptions that occur during execution.
It is a more powerful or destructive version of the method.
35. Which Rails helper would you use in the application view to protect against CSRF (Cross-Site Request Forgery) attacks?
Csrf_protection
Csrf_helper
Csrf_meta_tags
Csrf
36. In a Rails controller, what does the code params.permit(:name, :sku) do?
It filters out all parameters.
It filters out submitted form parameters that are not named :name or :sku to make forms more secure.
It raises an error if parameters that are not named :name or :sku are found.
It raises an error if the :name and :sku parameters are set to nil.
37. Review the code below. Which Ruby operator should be used to fill in the blank so that the sort method executes properly? [5,8,2,6,1,3].sort {|v1,v2| v1 ___ v2}
=>
<==>
<=>
||
38. Which statement about ActiveRecord models is true?
Each database column requres adding a matching attr_accessor declaration in the ActiveRecord model.
All attributes in an ActiveRecord model are read-only declared as writable using attr_accessible
An instance of an ActiveRecord model will have attributes that match the columns in a corresponding database table.
ActiveRecord models can have only attributes that have a matching database column
39. Which choice best describes the expected value of @result? @result = Article.first.tags.build(name: 'Urgent')
Either true or false
An unsaved Tag instance
A saved Tag instance
An array of Tag instances
40. Which part of the Rails framework is primarily responsible for making decisions about how to respond to a browser request?
View
Controller
ActiveRecord
Model
41. If User is an ActiveRecord class, which choice would be expected to return an array?
User.where(last_name: 'Smith')
User.find_or_create(last_name: 'Smith')
User.find_by_last_name('Smith')
User.find('Smith')
42. Which choice is not a valid Rails route?
Route
Match
Root
Get
43. Given a table of blog_posts and a related table of comments (comments made on each blog post), which ActiveRecord query will retrieve all blog posts with comments created during @range?
BlogPost.joins (:comments).where(comments: {created_at: @range})
BlogPost.where(['comments.created_at', @range])
BlogPost.preload (
BlogPost.includes (:comments).where('comments.created_at' => @range)
44. Which choice is an incorrect way to render a partial?
<%= render(:partial => 'shared/product') %>
<%= render('shared/product', :collection => @products) %>
<%= render(template: 'shared/product', with: @products) %>
<%= render('shared/product', locals: { product: @product }) %>
Submit