where we use attr_accessor and attr_accessible in rails ?
controller 1.0%
helper 0.0%
model 98.0%
view 0.0%
Choose the best way to implement sessions in Rails 3: A) Using CookieStore B) By creating a session table and setting config/initializers/session_store.rb with Rails.application.config.session_sto...
A 6.0%
B 89.0%
C 2.0%
B and C 1.0%
Consider the following code snippet: def index render end The corresponding index.html.erb view is as following: <html> <head> <title>Ruby on Rails sample application | <%=@title%></title> ...
The application will give an exception as @title variable is not defined in the controller. 15.0%
The HTML page will render with the title: Ruby on Rails sample application | <%=@title%>. 0.0%
The HTML page will render with the title: Ruby on Rails sample application |. 84.0%
The HTML page will render with the title: Ruby on Rails sample application. 0.0%
Consider the following information for a User view: user_path named route with value "/users/" @user = 1 Now, consider the following code in the HTML erb template: <%= link_to user_path(@user)...
a href='/users/1'>Angel</a 18.0%
a href='Angel'>/users/1</a 81.0%
a href='/users/1'>/users/1</a 0.0%
a href='Angel'>Angel</a 0.0%
For the String class, what's the difference between "#slice" and "#slice!"?
None, "#slice" is just an alias for "#slice!". 1.0%
There is no "#slice!" method in Ruby on Rails. 0.0%
"#slice" returns a new object, "#slice!" destructively updates — mutates — the object's value. 98.0%
Given below are two statements regarding the Ruby programming language: Statement X: "redo" restarts an iteration of the most internal loop, without checking loop condition. Statement Y: "retry" r...
Statement X is correct, but statement Y is incorrect. 3.0%
Statement X is incorrect, but statement Y is correct. 1.0%
Both statements are correct. 91.0%
Both statements are incorrect. 3.0%
Given the following code, where is the "party!" method available? module PartyAnimal def self.party! puts "Hard! Better! Faster! Stronger!" end end class Person include PartyA...
PartyAnimal.party! 96.0%
Person.party! 3.0%
Person.new.party! 0.0%
Both PartyAnimal.party! and Person.party! 0.0%
None of these 0.0%
How can a partial called "cart" be rendered from a controller called "ProductsController", assuming the partial is in a directory called "shared"?
render :partial => 'shared/cart' 89.0%
partial 'shared/cart' 9.0%
render 'cart' 1.0%
How can a value be stored so that it's shared across an entire request (i.e. make it accessible in controllers, views and models)?
Put it in a global variable. 14.0%
Create a Singleton and store it in a class variable. 79.0%
Store it in a thread locally. 6.0%
If a controller is named "Users", what would its helpers module be called?
UsersHelper 98.0%
UserControllerHelper 1.0%
UserHelp 0.0%
If a float is added to an integer, what is the class of the resulting number? i.e. 1.0 + 2
Integer 1.0%
Float 98.0%
BigDecimal 0.0%
If a method #decoupage(n) is described as O(n^2), what does that mean?
The fewest number of operations it will perform is n*n. 12.0%
The worst case run time is proportional to the size of the square of the method's input. 87.0%
The method operates by squaring the input. 0.0%
The return value for the method will be the length of the input squared. 0.0%
If a model called BlogComment is defined, what would its DB table be called?
blog_comment 2.0%
blogcomments 0.0%
blog_comments 98.0%
In a has_many association, what is the difference between build and new? // user.rb has_many :posts // post.rb belongs_to :user
'new' sets the foreign key while 'build' does not. 0.0%
'build' sets the foreign key while 'new' does not. 6.0%
'build' sets the foreign key and adds it to the collection. 93.0%
'new' sets the foreign key and adds it to the collection. 0.0%
In a Rails application, a Gemfile needs to be modified to make use of sqlite3-ruby gems. Which of the following options will use these gems, as per the new Gemfile?
install bundle Gemfile 0.0%
bundle install 100.0%
mate Gemfile 0.0%
gem bundle install 0.0%
In a Rails application, the developmental and production configuration are stored in the:
config/environment folder 97.0%
public folder 2.0%
spec folder 0.0%
task folder 0.0%
In a Rails Migration, which of the following will make a column unique, and then have it indexed?
add_index :table_name, :column_name, :unique => true 95.0%
add_index :unique => true ,:table_name, :column_name 0.0%
add_index :table_name, [:column_name_a, :unique => true ,:column_name_b], :unique => true 2.0%
None of these 2.0%
In order to enable locking on a table, which of the following columns is added?
lock_version column 97.0%
identity column 0.0%
primary key column 0.0%
lock_optimistic column 2.0%
In the case of Rails application performance optimization, select all valid ways to do assets compilation:
Running the rake task with the assets:precompile parameter when CSS and JavaScript files are updated. 48.0%
Set a true value for the config.assets.compile parameter in the config/environments/production.rb file. 40.0%
Implementing the Rails asset pipeline feature to minify JavaScript & CSS assets. 6.0%
All of these. 5.0%
Is an AJAX call synchronous or asynchronous?
Asynchronous 19.0%
Synchronous 2.0%
Either; it is configurable 78.0%
Rails automatically requires certain files in an application. Which of the following files are automatically included without an explicit 'require' being necessary?
All files in lib. 0.0%
All files in models, views, controllers, and files named rails.rb in lib. 2.0%
All files in models, views, controllers, and any init.rb in plugins. 93.0%
Only files explicitly referenced from an initializer in config/initializers. 4.0%
Select all incorrect statements regarding the Ruby Version Manager (RVM):
RVM is a command-line tool which allows developers to easily install, manage, and work with multiple Ruby environments from interpreters to sets of gems. 4.0%
RVM provides a revision control tool to maintain current and historical versions of files such as source code, web pages, and documentation. 92.0%
Test suites, rake tasks, benchmarks and gem commands can be run against multiple Ruby versions at the same time with RVM. 2.0%
RVM cannot automate the installation and maintenance of gems, it has to be done manually. 0.0%
Suppose a model is created as follows: rails generate model Sales rake db:migrate What would be the best way to completely undo these changes, assuming nothing else has changed in the mean...
rails reset models; rake db:rollback 0.0%
rails destroy model Sales; rake db:rollback 2.0%
rake db:rollback; rails rollback model Sales 0.0%
rake db:rollback; rails destroy model Sales 97.0%
The =~ operator is used to do inline Regular Expression matching, for instance: "function" =~ /fun/ "function" =~ /dinosaurs/ What are possible return values for the =~ matcher?
true, false 0.0%
"fun", nil 0.0%
1 and 0 only 0.0%
0 and nil only 10.0%
nil, 0, and any positive integer 90.0%
There is a table named Product in a Rails application. The program is required to fetch any 5 rows where the productid is 2. Which of the following is the correct option to perform this action?
Product.find(:productid=>2), :offset=>5 2.0%
Product.find(:productid=>2), :limit=>5 97.0%
Product.find(:productid=>2), :only=>5 0.0%
Unit tests are used to test which of the following components of Ruby on Rails?
Models 97.0%
Controllers 2.0%
Views 0.0%
Helper classes 0.0%
Users who are new to MVC design often ask how to query data from Views. Is this possible? And if so, is this a good idea?
It is not possible, because ActiveRecord queries cannot be made from Views. 0.0%
It is not possible, because Controllers do not provide enough information to the Views. 2.0%
It is possible, but it is a bad idea because Views should only be responsible for displaying objects passed to them. 97.0%
Using ERB for views, what filename should be given to a partial called 'login'?
partial_login.e 0.0%
_login.html.e 97.0%
login.html.e 2.0%
What component of Rails are tested with unit tests?
Models 100.0%
Controllers 0.0%
View helpers 0.0%
What declaration would you use to set the layout for a controller?
layout 'new_layout' 93.0%
set_layout 'new_layout' 6.0%
@layout = 'new_layout' 0.0%
What does REST stand for?
Ruby Enclosed Standard Templating 2.0%
Resource Standard Transfer 0.0%
REasonable Standards Testing 0.0%
REpresentational State Transfer 97.0%
Rights Enabled Safety Tunnel 0.0%
What does the 4xx series of HTTP errors represent?
They are intended for cases in which the server seems to have encountered an error. 74.0%
They are intended for cases in which the client seems to have encountered an error. 23.0%
They indicate that further action needs to be taken by the user agent in order to fulfill the request. 0.0%
They indicate that no further action can be taken by the user agent. 2.0%
What exception cannot be handled with the rescue_from method in the application controller? e.g class ApplicationControllers < ActionController::Base rescue_from Exception, with: error_handler ...
Server errors 80.0%
Record not found (404) 0.0%
Routing errors 11.0%
All of these 7.0%
What is best way to create primary key as a string field instead of integer in rails.
when creating a new table don't add primary key using this create_table users, :id => false do |t| t.string :id, :null => false ...... end execute("ALTER TABLE users ADD PRIMARY KEY (id)") if not using id as primary key then in users model add the following line class User < ActiveRecord::Base self.primary_key = "column_name" .... end 88.0%
you can add a key to column name to make it primary create_table users :id => false do |t| t.string :column_name, :primary => true end 11.0%
What is difference between "has_one" and "belong_to"?
"has_one" should be used in a model whose table have foreign keys while "belong_to" is used with an associated table. 5.0%
"belong_to" should be used in a model whose table have foreign keys while "has_one" is used with an associated table. 94.0%
The two are interchangeable. 0.0%
None of these. 0.0%
What is green-threading?
A design pattern where a fixed-size pool of threads is shared around a program. 8.0%
When threads are emulated by a virtual machine or interpreter. 91.0%
Where programs are run across multiple CPUs. 0.0%
What is output of following statements? 1) "".nil? == "".empty? && "".blank? == "".empty? 2) !"".nil? == "".empty? && "".blank? == "".empty? 3) nil.nil? == nil.empty? && nil.blank? == nil.empty? 4)...
1) false 2) true 3) NoMethodError: undefined method `empty?' for nil:NilClass 4) true 5) NoMethodError: undefined method `any?' for "":String 6) false 97.0%
1) false 2) NoMethodError: undefined method `empty?' for "":String 3) true 4) true 5) NoMethodError: undefined method `any?' for "":String 6) false 2.0%
1) false 2) true 3) true 4) true 5) false 6) false 0.0%
1) false 2) true 3) false 4) true 5) true 6) false 0.0%
What is the behavior of class variables with subclasses?
Subclasses inherit a default value for the class variable, which can then be modified for just the subclass. 8.0%
Class variables are shared between between all classes in the hierarchy. 91.0%
Class variables are not inherited. 0.0%
What is the best way to get the current request URL in Rails?
request.url 88.0%
request.request_uri 2.0%
request.fullpath 8.0%
request.current_path 0.0%
What is the convention for methods which end with a question mark? e.g. #all?, #kind_of?, directory?
They should always require arguments. 2.0%
They should always return a boolean value. 94.0%
They should always report a value of the object they're being called on. 2.0%
What is the difference between _url and _path while being used in routes?
_url is absolute while _path is relative. 97.0%
_path is relative while _path is absolute. 2.0%
_path is used in controllers while _url is used in views. 0.0%
_path is used in views while _url is used in controllers. 0.0%
What is the difference between :dependent => :destroy and :dependent => :delete_all in Rails?
There is no difference between the two; :dependent => :destroy and :dependent => :delete_all are semantically equivalent. 2.0%
In :destroy, associated objects are destroyed alongside the object by calling their :destroy method, while in :delete_all, they are destroyed immediately, without calling their :destroy method. 97.0%
In :delete_all, associated objects are destroyed alongside the object by calling their :destroy method, while in :destroy, they are destroyed immediately, without calling their individual :destroy methods. 0.0%
None of these. 0.0%
What is the output of the following code in Ruby? x= "A" + "B" puts x y= "C" << "D" puts y
AB CD 100.0%
AB C 0.0%
AB D 0.0%
AB DC 0.0%
What is the output of the following code? "test"*5
type casting error 5.0%
test5 0.0%
5 0.0%
testtesttesttesttest 94.0%
What is the output of the following code? puts "aeiou".sub(/[aeiou]/, '*')
* 2.0%
***** 2.0%
*eiou 94.0%
nil 0.0%
What is the output of the following code? $val = 20 print "Sample Text
" if $val
20 2.0%
Sample Text 97.0%
No output 0.0%
Syntax error 0.0%
What is the output of the following Ruby code? puts "The multiplication output of 10,10,2 is #{10*10*2}"
200. 0.0%
The multiplication output of 10,10,2 is #{10*10*2}. 2.0%
The multiplication output of 10,10,2 is 200. 97.0%
The code will give a syntax error. 0.0%
What is the recommended Rails way to iterate over records for display in a view?
Implicitly loop over a set of records, and send the partial being rendered a :collection. 100.0%
Use each to explicitly loop over a set of records. 0.0%
Use for to fetch individual records explicitly in a loop. 0.0%
What is the Singleton design pattern?
A class for which there is only ever one instance. 97.0%
A single feature application, intended to enhance usability by keeping things simple. 0.0%
A class which is never instanced, but acts as a container for methods which are used by it's subclasses. 2.0%
When a new controller named "admin2" is created, the JS and the CSS files are created in:
controllers 0.0%
helpers 0.0%
assets 97.0%
views 2.0%
When using full-page caching, what happens when an incoming request matches a page in the cache?
The web-server serves the file directly from disk, bypassing Rails. 93.0%
Rails checks to see if there is a cached page on disk and passes it onto the server. 6.0%
Rails checks its in-memory cache and passes the page onto the server. 0.0%
Which gem is used to install a debugger in Rails 3?
gem 'ruby-debug1' 0.0%
gem "ruby-debug19" 100.0%
gem "debugger19" 0.0%
gem "ruby-debugger" 0.0%
Which is the best way to add a page-specific JavaScript code in a Rails 3 app? <%= f.radio_button :rating, 'positive', :onclick => "$('some_div').show();" %>
<% content_for :head do %> <script type="text/javascript"> <%= render :partial => "my_view_javascript" </script> <% end %> Then in layout file <head> ... <%= yield :head %> </head> 59.0%
In the application_helper.rb file: def include_javascript (file) s = " <script type="text/javascript">" + render(:file => file) + "</script>" content_for(:head, raw(s)) end Then in your particular view (app/views/books/index.html.erb in this example) <% include_javascript 'books/index.js' %> 7.0%
In the controller: def get_script render :file => 'app/assessts/javascripts/' + params[:name] + '.js' end def get_page @script = '/' + params[:script_name] + '.js?body=1' render page end In View <script type="text/javascript",:src => @script> 0.0%
None of these 33.0%
Which of the following actions is fired by default when a new controller is created?
index 100.0%
run 0.0%
show 0.0%
login 0.0%
Which of the following assertions are used in testing views?
assert_valid 4.0%
assert_select_email 29.0%
assert_select_encoded 37.0%
css_select 27.0%
Which of the following choices will write routes for the API versioning scenario described below? /api/users returns a 301 to /api/v2/users /api/v1/users returns a 200 of users index at version 1 ...
namespace :api do namespace :v1 do resources :users end namespace :v2 do resources :users end match 'v:api/*path', :to => redirect("/api/v2/%{path}") match '*path', :to => redirect("/api/v2/%{path}") end 18.0%
namespace :api do resources :users end namespace :v2 do resources :users end match 'v:api/*path', :to => redirect("/api/v1/%{path}") match '*path', :to => redirect("/api/v1/%{path}") end 4.0%
namespace :api do scope :module => :v3, ¤t_api_routes namespace :v3, ¤t_api_routes namespace :v2, ¤t_api_routes namespace :v1, ¤t_api_routes match ":api/*path", :to => redirect("/api/v3/%{path}") end 0.0%
None of these 77.0%
Which of the following code samples will get the index of |page| inside of a loop?
<% @images.each.do |page,index| %> <% end %> 3.0%
<% @images.each_with_index do |page, index| %> <% end %> 93.0%
<% @images.collect.each.at_index do |page, index| %> <% end %> 0.0%
None of these 3.0%
Which of the following commands adds the data model info to the model file?
bundle install 3.0%
generate model 80.0%
annotate 16.0%
Rails server 0.0%
Which of the following commands will clear out sample users from the development database?
rake db:migrate 0.0%
rake db:reset 96.0%
rake db:rollback 3.0%
Which of the following commands will test a particular test case, given that the tests are contained in the file test/unit/demo_test.rb, and the particular test case is test_one?
$ ruby -Itest test/unit/demo_test.rb -n test_one 86.0%
$ ruby -Itest test/unit/demo_test.rb -a test_one 4.0%
$ ruby -Itest test/unit/demo_test.rb test_one 0.0%
$ ruby -Itest test/unit/demo_test.rb -t test_one 8.0%
Which of the following controller actions (by default) are best suited to handle the GET HTTP request?
index 38.0%
show 34.0%
create 1.0%
edit 24.0%
update 1.0%
Which of the following correctly handles the currency field? A) add_column :items, :price, :decimal, :precision => 8, :scale => 2 B) add_money :items, :price, currency: { present: false }
A 96.0%
B 3.0%
Both A and B are correct. 0.0%
Both A and B are incorrect. 0.0%
Which of the following HTML template languages are supported by Ruby?
Embedded Ruby 70.0%
HAML 21.0%
Mustache 5.0%
Razor 2.0%
Which of the following is not a built-in Rails caching strategy used to reduce database calls?
Page Caching 4.0%
Fragment Caching 4.0%
Object Caching 23.0%
Query Caching 66.0%
Which of the following is not true about log levels in Ruby on Rails?
The available log levels are: :debug, :info, :warn, :error, and :fatal, corresponding to the log level numbers from 1 up to 5 respectively. 50.0%
To check the current log level, the Rails.logger.level method has to be called. 2.0%
By default, each log is created under Rails.root/log/ and the log file name is environment_name.log. 5.0%
The default Rails log level is error in production mode and debug in development and test mode. 42.0%
Which of the following is the correct syntax for an input field of radio buttons in form_for?
<%= f.radio_button :contactmethod, 'sms' %> 91.0%
<%= f.radio_button_tag :contactmethod, 'sms' %> 4.0%
<%= radio_button_tag :contactmethod, 'sms' %> 0.0%
<%= f.radio_button "contactmethod", 'sms' %> 4.0%
Which of the following is the correct way to know the Rails root directory path?
RAILS_ROOT 0.0%
Rails.root 100.0%
Rails.root.show 0.0%
Rails.show.root 0.0%
Which of the following is the correct way to rollback a migration?
A migration cannot be rollbacked. 0.0%
rake db:rollback STEP=N (N is the migration number to be rollbacked) 92.0%
rake db:migrate:reset: (N) (N is the migration number to be rollbacked) 0.0%
rake db:rollback migration=N (N is the migration number to be rollbacked) 8.0%
Which of the following is the correct way to skip ActiveRecords in Rails 3?
ActiveRecords cannot be skipped. 0.0%
Use option -O while generating application template. 95.0%
Use option -SKIP_AR while generating the application template. 4.0%
Add new line SKIP: ACTIVERECORD in config.generators. 0.0%
Which of the following is the default way that Rails seeds data for tests?
Data Migrations 0.0%
Factories 8.0%
Fixture Factories 0.0%
Fixtures 92.0%
Which of the following is true about writing tests for a Ruby on Rails application?
Rails semi-automates the process of writing tests. It starts by producing skeleton test code in the background while models and controllers are being written. 4.0%
Running tests in Rails ensures that the code adheres to the desired functionality even after major code refactoring. 0.0%
Rails tests can simulate browser requests, and thus test the application's response without having to test it through a browser. 9.0%
All of these. 86.0%
Which of the following items are stored in the models subdirectory?
helper classes 0.0%
database classes 100.0%
HTML layout templates 0.0%
Config files 0.0%
Which of the following methods is used to check whether an object is valid or invalid?
.valid? and .invalid? 95.0%
valid() and invalid() 4.0%
isvalid and isinvalid 0.0%
Which of the following options is used to create a form HTML in the erb files?
form_for 100.0%
create_form 0.0%
form_do 0.0%
form 0.0%
Which of the following options will disable the rendering of the view associated with a controller action?
render :layout=>false 95.0%
render :layout=>nil 4.0%
render :layout=>disabled 0.0%
render :layout=>off 0.0%
Which of the following options, when passed as arguments, skips a particular validation?
:validate => skip 0.0%
:validate => off 0.0%
:validate => disable 4.0%
:validate => false 95.0%
Which of the following replaced the Prototype JavaScript library in Ruby on Rails as the default JavaScript library?
jQuery 100.0%
Ajax 0.0%
Script.aculo.us 0.0%
ajax-li 0.0%
Which of the following serves as a structural skeleton for all HTML pages created?
application.html.erb 92.0%
default.html.erb 0.0%
index.html.erb 0.0%
layout.html.erb 8.0%
Which of the following statements is incorrect?
Rails does not support ODBC connectivity. 96.0%
Rails can rollback database changes in development mode. 0.0%
Rails can work and connect with multiple databases. 4.0%
Rails database information is stored in the database.yml file. 0.0%
Which of the following validations in Rails checks for null fields?
validates_presence_of 96.0%
validates_length_of 0.0%
validates_confirmation_of 4.0%
validates_uniqueness_of 0.0%
Which of the following will disable browser page caching in Rails?
expire_page(:controller => 'products', :action => 'index') 91.0%
expire_fragment(:controller => 'products', :action => 'index') 4.0%
expire_page_fragment('all_available_products') 4.0%
expire_fragment('all_available_products') 0.0%
Which of the following will return a User object when used with a model which deals with a table named User?
User.new 36.0%
User.destroy 21.0%
User.find 40.0%
User.save 1.0%
Which part of the MVC stack does ERB or HAML typically participate in?
Class 0.0%
Controller 0.0%
Model 0.0%
Module 0.0%
View 100.0%
With the two models Hive and Bee; when creating a belongs_to association from the Bee model to Hive, what is the foreign key generated on Bee?
hive_id 96.0%
hives_id 3.0%
ee_id 0.0%