1. Which of the following will return a User object when used with a model which deals with a table named User?
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
// user.rb
has_many :posts
// post.rb
belongs_to :user
Answers:
"test"*5
Answers:
Answers:
Answers:
Answers:
/api/users returns a 301 to /api/v2/users
/api/v1/users returns a 200 of users index at version 1
/api/v3/users returns a 301 to /api/v2/users
/api/asdf/users returns a 301 to /api/v2/users
Answers:
puts “The multiplication output of 10,10,2 is #{10*10*2}”
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
module PartyAnimal
def self.party!
puts “Hard! Better! Faster! Stronger!”
end
end
class Person
include PartyAnimal
end
Answers:
Answers:
Answers:
x= “A” + “B”
puts x
y= “C” << “D”
puts y
Answers:
Answers:
e.g
class ApplicationControllers < ActionController::Base
rescue_from Exception, with: error_handler
……….
end
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Statement X: “redo” restarts an iteration of the most internal loop, without checking loop condition.
Statement Y: “retry” restarts the invocation of an iterator call. Also, arguments to the iterator are re-evaluated.Which of the following options is correct?
Answers:
A) Using CookieStore
B) By creating a session table and setting config/initializers/session_store.rb with Rails.application.config.session_store :active_record_store
C) By setting config/initializers/session_store.rb with Rails.application.config.session_store :active_record_store only
Answers:
Answers:
Answers:
Answers:
Answers:
puts “aeiou”.sub(/[aeiou]/, ‘*’)
Answers:
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 meantime?
Answers:
Answers:
Answers:
Answers:
Answers:
<%= f.radio_button :rating, ‘positive’, :onclick => “$(‘some_div’).show();” %>
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
def index
render
end
The corresponding index.html.erb view is as following:
<html>
<head>
<title>Ruby on Rails sample application | <%=@title%></title>
</head>
<body></body>
</html>
Which of the following options is correct?
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
- User.new
- User.destroy
- User.find
- User.save
Answers:
- Running the rake task with the assets:precompile parameter when CSS and JavaScript files are updated.
- Set a true value for the config.assets.compile parameter in the config/environments/production.rb file.
- Implementing the Rails asset pipeline feature to minify JavaScript & CSS assets.
- All of these.
Answers:
- request.url
- request.request_uri
- request.fullpath
- request.current_path
Answers:
- Put it in a global variable.
- Create a Singleton and store it in a class variable.
- Store it in a thread locally.
Answers:
- bundle install
- generate model
- annotate
- Rails server
Answers:
- Embedded Ruby
- HAML
- Mustache
- Razor
// user.rb
has_many :posts
// post.rb
belongs_to :user
Answers:
- ‘new’ sets the foreign key while ‘build’ does not.
- ‘build’ sets the foreign key while ‘new’ does not.
- ‘build’ sets the foreign key and adds it to the collection.
- ‘new’ sets the foreign key and adds it to the collection.
"test"*5
Answers:
- type casting error
- test5
- 5
- testtesttesttesttest
Answers:
- The web-server serves the file directly from disk, bypassing Rails.
- Rails checks to see if there is a cached page on disk and passes it onto the server.
- Rails checks its in-memory cache and passes the page onto the server.
Answers:
- _url is absolute while _path is relative.
- _path is relative while _path is absolute.
- _path is used in controllers while _url is used in views.
- _path is used in views while _url is used in controllers.
Answers:
- <% @images.each.do |page,index| %> <% end %>
- <% @images.each_with_index do |page, index| %> <% end %>
- <% @images.collect.each.at_index do |page, index| %> <% end %>
- None of these
/api/users returns a 301 to /api/v2/users
/api/v1/users returns a 200 of users index at version 1
/api/v3/users returns a 301 to /api/v2/users
/api/asdf/users returns a 301 to /api/v2/users
Answers:
- 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
- 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
- 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
- None of these
puts “The multiplication output of 10,10,2 is #{10*10*2}”
Answers:
- 200.
- The multiplication output of 10,10,2 is #{10*10*2}.
- The multiplication output of 10,10,2 is 200.
- The code will give a syntax error.
Answers:
- “has_one” should be used in a model whose table have foreign keys while “belong_to” is used with an associated table.
- “belong_to” should be used in a model whose table have foreign keys while “has_one” is used with an associated table.
- The two are interchangeable.
- None of these.
Answers:
- RAILS_ROOT
- Rails.root
- Rails.root.show
- Rails.show.root
Answers:
- 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
- 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
Answers:
- install bundle Gemfile
- bundle install
- mate Gemfile
- gem bundle install
Answers:
- Implicitly loop over a set of records, and send the partial being rendered a :collection.
- Use each to explicitly loop over a set of records.
- Use for to fetch individual records explicitly in a loop.
Answers:
- controller
- helper
- model
- view
module PartyAnimal
def self.party!
puts “Hard! Better! Faster! Stronger!”
end
end
class Person
include PartyAnimal
end
Answers:
- PartyAnimal.party!
- Person.party!
- Person.new.party!
- Both PartyAnimal.party! and Person.party!
- None of these
Answers:
- Class
- Controller
- Model
- Module
- View
Answers:
- helper classes
- database classes
- HTML layout templates
- Config files
x= “A” + “B”
puts x
y= “C” << “D”
puts y
Answers:
- AB CD
- AB C
- AB D
- AB DC
Answers:
- gem ‘ruby-debug1’
- gem “ruby-debug19”
- gem “debugger19”
- gem “ruby-debugger”
e.g
class ApplicationControllers < ActionController::Base
rescue_from Exception, with: error_handler
……….
end
Answers:
- Server errors
- Record not found (404)
- Routing errors
- All of these
Answers:
- Models
- Controllers
- View helpers
Answers:
- jQuery
- Ajax
- Script.aculo.us
- ajax-li
Answers:
- The fewest number of operations it will perform is n*n.
- The worst case run time is proportional to the size of the square of the method’s input.
- The method operates by squaring the input.
- The return value for the method will be the length of the input squared.
Answers:
- A design pattern where a fixed-size pool of threads is shared around a program.
- When threads are emulated by a virtual machine or interpreter.
- Where programs are run across multiple CPUs.
Answers:
- assert_valid
- assert_select_email
- assert_select_encoded
- css_select
Answers:
- Asynchronous
- Synchronous
- Either; it is configurable
Answers:
- rake db:migrate
- rake db:reset
- rake db:rollback
Statement X: “redo” restarts an iteration of the most internal loop, without checking loop condition.
Statement Y: “retry” restarts the invocation of an iterator call. Also, arguments to the iterator are re-evaluated.Which of the following options is correct?
Answers:
- Statement X is correct, but statement Y is incorrect.
- Statement X is incorrect, but statement Y is correct.
- Both statements are correct.
- Both statements are incorrect.
A) Using CookieStore
B) By creating a session table and setting config/initializers/session_store.rb with Rails.application.config.session_store :active_record_store
C) By setting config/initializers/session_store.rb with Rails.application.config.session_store :active_record_store only
Answers:
- A
- B
- C
- B and C
Answers:
- ActiveRecords cannot be skipped.
- Use option -O while generating application template.
- Use option -SKIP_AR while generating the application template.
- Add new line SKIP: ACTIVERECORD in config.generators.
Answers:
- Data Migrations
- Factories
- Fixture Factories
- Fixtures
Answers:
- :validate => skip
- :validate => off
- :validate => disable
- :validate => false
Answers:
- layout ‘new_layout’
- set_layout ‘new_layout’
- @layout = ‘new_layout’
puts “aeiou”.sub(/[aeiou]/, ‘*’)
Answers:
- *
- *****
- *eiou
- nil
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 meantime?
Answers:
- rails reset models; rake db:rollback
- rails destroy model Sales; rake db:rollback
- rake db:rollback; rails rollback model Sales
- rake db:rollback; rails destroy model Sales
Answers:
- There is no difference between the two; :dependent => :destroy and :dependent => :delete_all are semantically equivalent.
- 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.
- 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.
- None of these.
Answers:
- .valid? and .invalid?
- valid() and invalid()
- isvalid and isinvalid
Answers:
- A migration cannot be rollbacked.
- rake db:rollback STEP=N (N is the migration number to be rollbacked)
- rake db:migrate:reset: (N) (N is the migration number to be rollbacked)
- rake db:rollback migration=N (N is the migration number to be rollbacked)
Answers:
- <%= f.radio_button :contactmethod, ‘sms’ %>
- <%= f.radio_button_tag :contactmethod, ‘sms’ %>
- <%= radio_button_tag :contactmethod, ‘sms’ %>
- <%= f.radio_button “contactmethod”, ‘sms’ %>
<%= f.radio_button :rating, ‘positive’, :onclick => “$(‘some_div’).show();” %>
Answers:
- <% content_for :head do %> <script type=”text/javascript”> <%= render :partial => “my_view_javascript” </script> <% end %> Then in layout file <head> … <%= yield :head %> </head>
- 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’ %>
- 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>
- None of these
Answers:
- lock_version column
- identity column
- primary key column
- lock_optimistic column
Answers:
- Integer
- Float
- BigDecimal
Answers:
- add_index :table_name, :column_name, :unique => true
- add_index :unique => true ,:table_name, :column_name
- add_index :table_name, [:column_name_a, :unique => true ,:column_name_b], :unique => true
- None of these
Answers:
- expire_page(:controller => ‘products’, :action => ‘index’)
- expire_fragment(:controller => ‘products’, :action => ‘index’)
- expire_page_fragment(‘all_available_products’)
- expire_fragment(‘all_available_products’)
Answers:
- $ ruby -Itest test/unit/demo_test.rb -n test_one
- $ ruby -Itest test/unit/demo_test.rb -a test_one
- $ ruby -Itest test/unit/demo_test.rb test_one
- $ ruby -Itest test/unit/demo_test.rb -t test_one
def index
render
end
The corresponding index.html.erb view is as following:
<html>
<head>
<title>Ruby on Rails sample application | <%=@title%></title>
</head>
<body></body>
</html>
Which of the following options is correct?
Answers:
- The application will give an exception as @title variable is not defined in the controller.
- The HTML page will render with the title: Ruby on Rails sample application | <%=@title%>.
- The HTML page will render with the title: Ruby on Rails sample application |.
- The HTML page will render with the title: Ruby on Rails sample application.
Answers:
- Models
- Controllers
- Views
- Helper classes
Answers:
- UsersHelper
- UserControllerHelper
- UserHelp
Answers:
- application.html.erb
- default.html.erb
- index.html.erb
- layout.html.erb
Answers:
- Rails does not support ODBC connectivity.
- Rails can rollback database changes in development mode.
- Rails can work and connect with multiple databases.
- Rails database information is stored in the database.yml file.
Answers:
- A class for which there is only ever one instance.
- A single feature application, intended to enhance usability by keeping things simple.
- A class which is never instanced, but acts as a container for methods which are used by it’s subclasses.
Answers:
- It is not possible, because ActiveRecord queries cannot be made from Views.
- It is not possible, because Controllers do not provide enough information to the Views.
- It is possible, but it is a bad idea because Views should only be responsible for displaying objects passed to them.
Answers:
- Ruby Enclosed Standard Templating
- Resource Standard Transfer
- REasonable Standards Testing
- REpresentational State Transfer
- Rights Enabled Safety Tunnel
No comments:
Post a Comment