MCQs > IT & Programming > Ruby On Rails MCQs > Basic Ruby on Rails MCQs

Basic Ruby on Rails MCQ

1. Which code sample will skip running the login_required "before" filter on the get_posts controller action?

Answer

Correct Answer: Skip_before_action :login_required, only: [:get_posts]

Note: This Question is unanswered, help us to find answer for this one

2. Which choice is an incorrect way to render a partial?

Answer

Correct Answer: <%= render(template: 'shared/product', with: @products) %>

Note: This Question is unanswered, help us to find answer for this one

3. 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?

Answer

Correct Answer: BlogPost.joins (:comments).where(comments: {created_at: @range})

Note: This Question is unanswered, help us to find answer for this one

4. Which choice is not a valid Rails route?

Answer

Correct Answer: Route

Note: This Question is unanswered, help us to find answer for this one

5. If User is an ActiveRecord class, which choice would be expected to return an array?

Answer

Correct Answer: User.where(last_name: 'Smith')

Note: This Question is unanswered, help us to find answer for this one

6. Which part of the Rails framework is primarily responsible for making decisions about how to respond to a browser request?

Answer

Correct Answer: Controller

Note: This Question is unanswered, help us to find answer for this one

7. Which choice best describes the expected value of @result? @result = Article.first.tags.build(name: 'Urgent')

Answer

Correct Answer: An unsaved Tag instance

Note: This Question is unanswered, help us to find answer for this one

8. Which statement about ActiveRecord models is true?

Answer

Correct Answer: An instance of an ActiveRecord model will have attributes that match the columns in a corresponding database table.

Note: This Question is unanswered, help us to find answer for this one

9. 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}

Answer

Correct Answer: <=>

Note: This Question is unanswered, help us to find answer for this one

10. In a Rails controller, what does the code params.permit(:name, :sku) do?

Answer

Correct Answer: It filters out submitted form parameters that are not named :name or :sku to make forms more secure.

Note: This Question is unanswered, help us to find answer for this one

11. Which Rails helper would you use in the application view to protect against CSRF (Cross-Site Request Forgery) attacks?

Answer

Correct Answer: Csrf_meta_tags

Note: This Question is unanswered, help us to find answer for this one

12. When Ruby methods add an exclamation point at the end of their name (such as sort!), what does it typically indicate?

Answer

Correct Answer: It is a more powerful or destructive version of the method.

Note: This Question is unanswered, help us to find answer for this one

13. What is a popular alternative template language for generating views in a Rails app that is focused on simple abstracted markup?

Answer

Correct Answer: Haml

Note: This Question is unanswered, help us to find answer for this one

14. If a model class is named Product, in which database table will ActiveRecord store and retrieve model instances?

Answer

Correct Answer: Products

Note: This Question is unanswered, help us to find answer for this one

15. What is the correct way to generate a ProductsController with an index action using only the command-line tools bundled with Rails?

Answer

Correct Answer: Rails generate controller Products index

Note: This Question is unanswered, help us to find answer for this one

16. In Rails, what caching stores can be used?

Answer

Correct Answer: MemoryStore, FileStore, MemCacheStore, RedisCacheStore, and NullStore

Note: This Question is unanswered, help us to find answer for this one

17. If the Rails asset pipeline is being used to serve JavaScript files, how would you include a link to one of those JavaScript files in a view?

Answer

Correct Answer: <%= javascript_include_tag 'main' %>

Note: This Question is unanswered, help us to find answer for this one

18. Where should you put images, JavaScript, and CSS so that they get processed by the asset pipeline?

Answer

Correct Answer: App/assets

Note: This Question is unanswered, help us to find answer for this one

19. How would you render a view using a different layout in an ERB HTML view?

Answer

Correct Answer: <% render 'view', layout: 'mobile' %>

Note: This Question is unanswered, help us to find answer for this one

20. How do you add Ruby code inside Rails views and have its result outputted in the HTML file?

Answer

Correct Answer: Create an embedded Ruby file (.html.erb) and surround the Ruby code with <%= %>.

Note: This Question is unanswered, help us to find answer for this one

21. In ActiveRecord, what is the difference between the has_many and has_many :through associations?

Answer

Correct Answer: Both are one-to-many associations but with has_many :through, the declaring model can associate through a third model.

Note: This Question is unanswered, help us to find answer for this one

22. You are using an existing database that has a table named coffee_orders. What would the ActiveRecord model be named in order to use that table?

Answer

Correct Answer: CoffeeOrder

Note: This Question is unanswered, help us to find answer for this one

23. When using an ActiveRecord model, which method will create the model instance in memory and save it to the database?

Answer

Correct Answer: Create

Note: This Question is unanswered, help us to find answer for this one

24. What is the reason for using Concerns in Rails?

Answer

Correct Answer: Concerns allow modularity and code reuse in models, controllers, and other classes.

Note: This Question is unanswered, help us to find answer for this one

25. In Rails, how would you cache a partial template that is rendered?

Answer

Correct Answer: Render partial: ‘shared/menu’, cached: true

Note: This Question is unanswered, help us to find answer for this one

26. Given the URL helper product_path(@product), which statement would be expected to be false?

Answer

Correct Answer: If sent using the POST HTTP method, the URL would create a new product in the database.

Note: This Question is unanswered, help us to find answer for this one

27. For a Rails validator, how would you define an error message for the model attribute address with the message "This address is invalid"?

Answer

Correct Answer: Model.errors[:address] <<

Note: This Question is unanswered, help us to find answer for this one

28. How would you generate a drop-down menu that allows the user to select from a collection of product names?

Answer

Correct Answer: <%= collection_select(:product, :product_id, Product.all, :id, :name) %>

Note: This Question is unanswered, help us to find answer for this one

29. When a validation of a field in a Rails model fails, where are the messages for validation errors stored?

Answer

Correct Answer: My_model.errors[:field]

Note: This Question is unanswered, help us to find answer for this one

30. Are instance variables set within a controller method accessible within a view?

Answer

Correct Answer: Yes, any instance variables that are set in an action method on a controller can be accessed and displayed in a view.

Note: This Question is unanswered, help us to find answer for this one

31. Which ActiveRecord query prevents SQL injection?

Answer

Correct Answer: Product.where(

Note: This Question is unanswered, help us to find answer for this one

32. Which choice includes standard REST HTTP verbs?

Answer

Correct Answer: GET, POST, PATCH, DELETE

Note: This Question is unanswered, help us to find answer for this one

33. In Rails, which code would you use to define a route that handles both the PUT and PATCH REST HTTP verbs?

Answer

Correct Answer: Match 'items', to 'items#update', via: [:put, :patch]

Note: This Question is unanswered, help us to find answer for this one

34. Which module can you use to encapsulate a cohesive chunk of functionality into a mixin?

Answer

Correct Answer: ActiveSupport::Concern

Note: This Question is unanswered, help us to find answer for this one

35. What is before_action (formerly known as before_filter)?

Answer

Correct Answer: A method in a controller that is executed before the controller action method

Note: This Question is unanswered, help us to find answer for this one

36. Which statement correctly describes a difference between the form helper methods form_tag and form_for?

Answer

Correct Answer: The form_tag method typically expects a URL as its first argument, while the form_for method typically expects a model object.

Note: This Question is unanswered, help us to find answer for this one

37. Within a Rails controller, which code will prevent the parent controller's before_action :get_feature from running?

Answer

Correct Answer: Skip_before_action :get_feature

Note: This Question is unanswered, help us to find answer for this one

38. When rendering a partial in a view, how would you pass local variables for rendering?

Answer

Correct Answer: <%= render partial:

Note: This Question is unanswered, help us to find answer for this one

39. What does the expression x ||= y mean?

Answer

Correct Answer: x = y when x == false, otherwise x remains unchanged

Note: This Question is unanswered, help us to find answer for this one

40. Which of the following gems is used for authentication in Ruby on Rails? (check any that apply)

Answer

Correct Answer: Devise
OmniAuth
Authlogic

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

41.

What is the CGI Library? (check any that apply)

Answer

Correct Answer: CGI data processing routines
Part of the Ruby standard library

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

42.

The send_data method has the following options? send_data(data, options = {})

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

43.

Which of these codes will print correct date?

format('Birthday: #{month}/#{day}/#{year}', day: 14, month: 11, year: 1994) format('Birthday: %d/%d/%d', 11, 14, 1994)

format('Birthday: %{month}/%{day}/%{year}', day: 14, month: 11, year: 1994) format('Birthday: %{month}/%{day}/%{year}', 11, 14, 1994)

 

Answer

Correct Answer: 2nd
3rd

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

44.

Which of these files are located by default in "config” directory? (check any that apply)

Answer

Correct Answer: application.rb
environment.rb

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

45.

Which of these filters do no exist in Rails controller? (check any that apply)

Answer

Correct Answer: skip_action_callback
skip_before_callback
skip_after_callback

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

46.

Which of these folders do not exist in folder “app” in Rails 5? (check any that apply)

Answer

Correct Answer: vendor
services

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

47.

Which of these URL's will not be created by method resources :posts in routes.rb?

Answer

Correct Answer: POST /posts/create
DELETE /posts/:id/delete

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

48.

Which of these statements about Ruby on Rails 5 are false?

Answer

Correct Answer: Relation "has_one" is required by default
Terminal command "rails" replaced by "rake"

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

49.

Why would let() be used in rspec?

Answer

Correct Answer: let() always invoked before initialization

Note: This Question is unanswered, help us to find answer for this one

50.

What is the SQL equivalent of following code? user=User.take(3)

Answer

Correct Answer: SELECT *from users limit 3

Note: This Question is unanswered, help us to find answer for this one

51.

Which of the following code snippet can be used to include all javascript files?

Answer

Correct Answer: <%= javascript_include_tag :defaults %>

Note: This Question is unanswered, help us to find answer for this one

52.

Which of the following code snippet can be used to include all javascript files?

Answer

Correct Answer: http_basic_authenticate_with

Note: This Question is unanswered, help us to find answer for this one

53.

Which following command will you use in Updates Ruby in the latest version?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

54.

While installing Ruby, why do you sometimes get a missing "psych” error?

Answer

Correct Answer: It seems your Ruby installation is missing psych (for YAML output). To eliminate this warning, please install libyaml and reinstall your Ruby.

Note: This Question is unanswered, help us to find answer for this one

55.

Which of the following code is correct about Creating links

Answer

Correct Answer: <%= link_to “Button”, {:action => “action_name”, :id => product}, :confirm => “some text here” %>

Note: This Question is unanswered, help us to find answer for this one

56.

What is the top-level model class added in Ruby on Rails 5?

Answer

Correct Answer: ApplicationRecord

Note: This Question is unanswered, help us to find answer for this one

57.

Which type of field is recommended for storing “enum" in Rails?

Answer

Correct Answer: integer

Note: This Question is unanswered, help us to find answer for this one

58.

Which of these servers is the default development server for Ruby on Rails 5?

Answer

Correct Answer: Puma

Note: This Question is unanswered, help us to find answer for this one

59.

Which of these model methods will be generated by this code? enum state: { blocked: 0, active: 1 }

Answer

Correct Answer: Model.states

Note: This Question is unanswered, help us to find answer for this one

60.

Which of these methods catch Exception in Rails controllers?

Answer

Correct Answer: rescue_from

Note: This Question is unanswered, help us to find answer for this one

61.

Which of these routes is not generated by “resource :user”?

Answer

Correct Answer: GET /user/new

Note: This Question is unanswered, help us to find answer for this one

62.

Which of the following open directly is correct about Open URI?

Answer

Correct Answer: open('http://www.example.com') { | data | results = data.read }

Note: This Question is unanswered, help us to find answer for this one

63.

Which of these codes will raise an exception? class Person def name 'Andrew' end end # 1. person = Person.new person .name # 2. person = Person.new person. name # 3. Person .new .name # 4. Person .name

Answer

Correct Answer: None of these

Note: This Question is unanswered, help us to find answer for this one

64.

Which of the following is the correct way to add a field in a signup that is not present in the User Model?

Answer

Correct Answer: Use a nested attribute with the Devise Model.

Note: This Question is unanswered, help us to find answer for this one

65.

Which of these expressions is equivalent to this code? a ||= "string"

Answer

Correct Answer: a || a = "string"

Note: This Question is unanswered, help us to find answer for this one

66.

Which of the following represents the inverse of a has_one association?

Answer

Correct Answer: belongs_to

Note: This Question is unanswered, help us to find answer for this one

67.

In order to use optimistic locking, the table needs to have a column called ___________ of type integer.

Answer

Correct Answer: lock_version

Note: This Question is unanswered, help us to find answer for this one

68.

Which character is used to declare a global variable?

Answer

Correct Answer: $

Note: This Question is unanswered, help us to find answer for this one

69.

Which notation is used to create class variables?

Answer

Correct Answer: @@

Note: This Question is unanswered, help us to find answer for this one

70.

render method does not accept ________________

Answer

Correct Answer: language

Note: This Question is unanswered, help us to find answer for this one

71.

Which method is used to render partial templates as part of a view?

Answer

Correct Answer: render

Note: This Question is unanswered, help us to find answer for this one

72.

Which of the following types of association is not supported by ActiveRecord?

Answer

Correct Answer: many-to-one

Note: This Question is unanswered, help us to find answer for this one

73.

Which helper should be used when your model has association with other models and they also need to be validated?

Answer

Correct Answer: validates_associated

Note: This Question is unanswered, help us to find answer for this one

74.

State whether True or False The find method will raise an ActiveRecord::RecordNotFound exception unless a matching record is found for all the supplied primary keys.

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

75.

What is the difference between find() and find_by_id() method?

Answer

Correct Answer: find() will raise an error in case record does not exist for a given primary key whereas find_by_id() will not raise an error and will return nil

Note: This Question is unanswered, help us to find answer for this one

76.

How to disable protection of CSRF attacks for API requests?

Answer

Correct Answer: protect_from_forgery with: :null_session

Note: This Question is unanswered, help us to find answer for this one

77.

Which method is used in views to prevent CSRF attack?

Answer

Correct Answer: csrf_meta_tag

Note: This Question is unanswered, help us to find answer for this one

78.

Which of the following methods can be used inside a controller to prevent CSRF attack?

Answer

Correct Answer: protect_from_forgery

Note: This Question is unanswered, help us to find answer for this one

79.

What is the difference between Lambdas and procs?

Answer

Correct Answer: Lambdas check the number of arguments passed and will return an error if you try to pass the wrong number while Procs set extra variables to nil

Note: This Question is unanswered, help us to find answer for this one

80.

Which file contains the database credentials of an RoR application?

Answer

Correct Answer: database.yml

Note: This Question is unanswered, help us to find answer for this one

81.

Which of the following rake commands can be used to load a schema.rb file into the database?

Answer

Correct Answer: rake:db:schema:load

Note: This Question is unanswered, help us to find answer for this one

82.

Which file contains the Gem requirements of an RoR App?

Answer

Correct Answer: config

Note: This Question is unanswered, help us to find answer for this one

83.

Which of the following command is used to list all the routes of an RoR application?

Answer

Correct Answer: rake routes

Note: This Question is unanswered, help us to find answer for this one

84.

Which of the following is used to achieve multiple inheritance in Ruby?

Answer

Correct Answer: mixin

Note: This Question is unanswered, help us to find answer for this one

85.

Which declaration can be used to override the default layout conventions in your controllers?

Answer

Correct Answer: layout

Note: This Question is unanswered, help us to find answer for this one

86.

Which of the following loops is not supported by Ruby?

Answer

Correct Answer: Unless

Note: This Question is unanswered, help us to find answer for this one

87.

The belongs_to association supports following options?

A)     :autosavename, :class_id

B)     :primary_key, :validate, :optional

C)     :conuter_cache, :inverse_of, :foreign_key

D)     :dependent, :polymorphic, :touch


Answer

Correct Answer: B, C & D

Note: This Question is unanswered, help us to find answer for this one

88.

The has_one association supports following options?

Answer

Correct Answer: E)C,D

Note: This Question is unanswered, help us to find answer for this one

89.

Which of these options for “dependent” do not exist in Rails?

Answer

Correct Answer: All of these options exist

Note: This Question is unanswered, help us to find answer for this one

90.

How is it possible to create combined unique index for two fields?

Answer

Correct Answer: add_index :project_users, [:user_id, :project_id], unique: true

Note: This Question is unanswered, help us to find answer for this one

91.

How do you permit nester attributes in Rails controllers for such model? class User has_one :profile accepts_nested_attributes_for :profile end

Answer

Correct Answer: params.require(:user).permit(:email, profile_attributes: [:id, :_destroy])

Note: This Question is unanswered, help us to find answer for this one

92. Which of the following statements are correct about Types of Templates? (choose all that apply)

Answer

Correct Answer: rxml,Files with Ruby code using the Builder library to generate XML

Note: This Question is unanswered, help us to find answer for this one

93.

The following methods skip validations, and will save the object to the database regardless of its validity?

Answer

Correct Answer: E)A,B,C

Note: This Question is unanswered, help us to find answer for this one

94.

What is the difference between "has_many :through" and "has_and_belongs_to_many"?

Answer

Correct Answer: You should use "has_and_belongs_to_many" if you need validations, callbacks or extra attributes on the join model

Note: This Question is unanswered, help us to find answer for this one

95.

What is the purpose of using below code in filter_parameter_logging.rb? Rails.application.config.filter_parameters += [:password]

Answer

Correct Answer: Hide "password" parameter in applications logs

Note: This Question is unanswered, help us to find answer for this one

96.

A controller is a server-side _____ of Rails that responds to external requests from the web server to the application?

Answer

Correct Answer: Component

Note: This Question is unanswered, help us to find answer for this one

97.

In Ruby on Rails, an action is typically a basic ____ that describes how to respond to a specific external web-browser request?

Answer

Correct Answer: Unit

Note: This Question is unanswered, help us to find answer for this one

98.

Which of the following instances are variables in your functional tests? (check any that apply)

Answer

Correct Answer: @controller - The controller processing the request
@request - The request object
@response - The response object

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

99.

What are the Available callbacks? (check any that apply)

Answer

Correct Answer: around_enqueue
after_enqueue
before_perform
around_perform

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

100.

Which of these is not a valid Bundler command?

Answer

Correct Answer: bundle deps

Note: This Question is unanswered, help us to find answer for this one

101.

What are the asset tag helpers available in Rails? (check any that apply)

Answer

Correct Answer: auto_discovery_link_tag
stylesheet_link_tag
image_tag

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

102.

The following methods trigger validations, and will save the object to the database only if the object is valid? (check any that apply)

Answer

Correct Answer: create
create!
update

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

103.

Calls to the render method generally accept using the following options?

Answer

Correct Answer: E)C,D

Note: This Question is unanswered, help us to find answer for this one

104.

What is the lowest version of Ruby supported by Ruby on Rails 5?

Answer

Correct Answer: Ruby 2.2.2

Note: This Question is unanswered, help us to find answer for this one

105.

Which of the following statements is correct?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

106.

Please select the True statements from the following:

Answer

Correct Answer: ActiveRecord - Talks to the database system and creates Ruby objects modeled on the database tables
ActionController - Manipulates ActiveRecord objects, loads data into variables for use in ActionView templates and uses CGI library to process form data held in CGI variables
ActionView - Fills ERB templates with data processed by ActionController, then hands the resulting HTML to the Web server

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

107.

Which of the following types of callbacks are available in ROR?

Answer

Correct Answer: D) B & C

Note: This Question is unanswered, help us to find answer for this one

108.

What is the difference between jruby and ruby?

Answer

Correct Answer: All of the above.

Note: This Question is unanswered, help us to find answer for this one

109.

Which of these options is right to create default scope of model in Rails?

Answer

Correct Answer: default_scope -> { order(:position) }

Note: This Question is unanswered, help us to find answer for this one

110.

Which of these files determine Ruby version and gemset for RVM library?

Answer

Correct Answer: .ruby-version, .ruby-gemset

Note: This Question is unanswered, help us to find answer for this one

111.

Which of the following statements is true regarding the find_or_create method in Ruby on Rails?

Answer

Correct Answer: It can find multiple arguments by using Model.find_or_create_by_name('name here'). It will first find the record and if it doesn't exist it will create it.

Note: This Question is unanswered, help us to find answer for this one

112.

Which of the following protects "NOT NULL" fields against missing a user input?

Answer

Correct Answer: validates_presence_of

Note: This Question is unanswered, help us to find answer for this one

113.

Which of the following is not an advantage of using an integrated development environment (IDE) for Rails ,compared with using a simple text editor?

Answer

Correct Answer: smaller memory footprint

Note: This Question is unanswered, help us to find answer for this one

114.

How can the Heroku deprecation warning be removed from a Rails plugin that has been used?

Answer

Correct Answer: ActiveSupport::Deprecation.silenced = true

Note: This Question is unanswered, help us to find answer for this one

115.

What is TDD is rails3?

Answer

Correct Answer: TDD directs focus on testing.

Note: This Question is unanswered, help us to find answer for this one

116.

Which of these tools are for checking Ruby code styling?

Answer

Correct Answer: Rubocop

Note: This Question is unanswered, help us to find answer for this one

117.

The asset tag helpers do not verify the existence of the assets at the specified locations.

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

118.

Which of the following validations are supported by models?

Answer

Correct Answer: Presence validation

Note: This Question is unanswered, help us to find answer for this one

119.

After executing the following code, what will the value of foo be? foo = 'bar' wom = Proc.new {|foo| foo = 'baz'} wom.call('pling')

Answer

Correct Answer: "bar"

Note: This Question is unanswered, help us to find answer for this one

120.

Which of the following will return a User object when used with a model which deals with a table named User?

 

Answer

Correct Answer: User.new

Note: This Question is unanswered, help us to find answer for this one

121.

Which of the following options will correctly show an image in the HTML ERB template in Rails?

 

Answer

Correct Answer: <%= image_tag("logo.png", :alt=>"Sample Logo", :class=>"round" %>

Note: This Question is unanswered, help us to find answer for this one

122.

Which of the following validations checks if a passed value is an enumeration and falls in the given range?

Answer

Correct Answer: validates_inclusion_of

Note: This Question is unanswered, help us to find answer for this one

123.

Which of the following will change a Rails 3 app to run in production mode?

Answer

Correct Answer: rails s -e production

Note: This Question is unanswered, help us to find answer for this one

124.

Given below are two statements regarding Rails testing: Statement X: Unit tests are used to test models. Statement Y: Functional tests are used to test controllers. Which of the following statements is true?

Answer

Correct Answer: Both statements X and Y are correct.

Note: This Question is unanswered, help us to find answer for this one

125.

During the deployment of the Rails application through Git, you want certain files to be ignored. Which of the following files performs that operation?

Answer

Correct Answer: .gitignore

Note: This Question is unanswered, help us to find answer for this one

126.

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?

Answer

Correct Answer: bundle install

Note: This Question is unanswered, help us to find answer for this one

127.

Which of the following options will create a new Rails application with default templates?

Answer

Correct Answer: rails new <application _name>

Note: This Question is unanswered, help us to find answer for this one

128.

If we need to associate one model with many others, what associations should we use?

Answer

Correct Answer: has_many, belongs_to

Note: This Question is unanswered, help us to find answer for this one

129.

Which of the following options will create a many-to-many relation between the 'users' and the 'jobs' tables?

Answer

Correct Answer: users_jobs

Note: This Question is unanswered, help us to find answer for this one

130.

For the String class, when using #gsub! what are the potential return values?

Answer

Correct Answer: nil or the string instance

Note: This Question is unanswered, help us to find answer for this one

131.

What is the purpose of the model in an MVC architecture framework such as Ruby on Rails?

Answer

Correct Answer: The model houses all the code that relates to data.

Note: This Question is unanswered, help us to find answer for this one

132.

Which of the following statements regarding models in Ruby on Rails is correct?

Answer

Correct Answer: The fetching of data from database is performed by models.

Note: This Question is unanswered, help us to find answer for this one

133.

Which of the following actions is fired by default when a new controller is created?

Answer

Correct Answer: index

Note: This Question is unanswered, help us to find answer for this one

134.

Which of the following options is used to create a form HTML in the erb files?

Answer

Correct Answer: form_for

Note: This Question is unanswered, help us to find answer for this one

135.

The =~ operator is used to do inline Regular Expression matching, for instance:
"function" =~ /fun/
"function" =~ /dinosaurs/
What are possible return values for the =~ matcher?

Answer

Correct Answer: nil, 0, and any positive integer

Note: This Question is unanswered, help us to find answer for this one

136.

Which of the following options will disable the rendering of the view associated with a controller action?

Answer

Correct Answer: render :layout=>false

Note: This Question is unanswered, help us to find answer for this one

137.

What is the output of the following code?
$val = 20
print "Sample Text\n" if $val

Answer

Correct Answer: Sample Text

Note: This Question is unanswered, help us to find answer for this one

138.

If a model called BlogComment is defined, what would its DB table be blog_commentcalled?

Answer

Correct Answer: blog_comments

Note: This Question is unanswered, help us to find answer for this one

139.

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), "Angel" %>
What will be the HTML output of this code?

Answer

Correct Answer: a href='/users/1'>Angel</a

Note: This Question is unanswered, help us to find answer for this one

140.

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?

Answer

Correct Answer: Product.find(:productid=>2), :limit=>5

Note: This Question is unanswered, help us to find answer for this one

141.

What is the behavior of class variables with subclasses?

Answer

Correct Answer: Class variables are shared between between all classes in the hierarchy.

Note: This Question is unanswered, help us to find answer for this one

142.

Which of the following is true about writing tests for a Ruby on Rails application?

Answer

Correct Answer: 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.

Note: This Question is unanswered, help us to find answer for this one

143.

Rails automatically requires certain files in an application. Which of the following files are automatically included without an explicit 'require' being necessary?

Answer

Correct Answer: All files in models, views, controllers, and any init.rb in plugins.

Note: This Question is unanswered, help us to find answer for this one

144.

Which of the following controller actions (by default) are best suited to handle the GET HTTP request?

Answer

Correct Answer: index

Note: This Question is unanswered, help us to find answer for this one

145.

For the String class, what's the difference between "#slice" and "#slice!"?

Answer

Correct Answer: "#slice" returns a new object, "#slice!" destructively updates — mutates — the object's value.

Note: This Question is unanswered, help us to find answer for this one

146.

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) !"".blank? == "".present?
5) "".any? == !"".empty?
6) " ".blank? == " ".empty?

Answer

Correct Answer: 1) false 2) true 3) false 4) true 5) true 6) false

Note: This Question is unanswered, help us to find answer for this one

147.

Using ERB for views, what filename should be given to a partial called 'login'?

Answer

Correct Answer: _login.html.e

Note: This Question is unanswered, help us to find answer for this one

148.

Which of the following validations in Rails checks for null fields?

Answer

Correct Answer: validates_presence_of

Note: This Question is unanswered, help us to find answer for this one

149.

What does the 4xx series of HTTP errors represent?

Answer

Correct Answer: They are intended for cases in which the client seems to have encountered an error.

Note: This Question is unanswered, help us to find answer for this one

150.

How can a partial called "cart" be rendered from a controller called "ProductsController", assuming the partial is in a directory called "shared"?

Answer

Correct Answer: render :partial => 'shared/cart'

Note: This Question is unanswered, help us to find answer for this one

151.

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 }

Answer

Correct Answer: A

Note: This Question is unanswered, help us to find answer for this one

152.

What is the convention for methods which end with a question mark?
e.g. #all?, #kind_of?, directory?

Answer

Correct Answer: They should always return a boolean value.

Note: This Question is unanswered, help us to find answer for this one

153.

In a Rails application, the developmental and production configuration are stored in the:

Answer

Correct Answer: config/environments folder

Note: This Question is unanswered, help us to find answer for this one

154.

Which of the following is not a built-in Rails caching strategy used to reduce database calls?

Answer

Correct Answer: Object Caching

Note: This Question is unanswered, help us to find answer for this one

155.

Select all incorrect statements regarding the Ruby Version Manager (RVM):

Answer

Correct Answer: RVM provides a revision control tool to maintain current and historical versions of files such as source code, web pages, and documentation.

Note: This Question is unanswered, help us to find answer for this one

156.

When a new controller named "admin2" is created, the JS and the CSS files are created in:

Answer

Correct Answer: assets

Note: This Question is unanswered, help us to find answer for this one

157.

Which of the following is not true about log levels in Ruby on Rails?

Answer

Correct Answer: The available log levels are: :debug, :info, :warn, :error, and :fatal, corresponding to the log level numbers from 1 up to 5 respectively.

Note: This Question is unanswered, help us to find answer for this one

158.

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?

Answer

Correct Answer: hive_id

Note: This Question is unanswered, help us to find answer for this one

159.

What does REST stand for?

Answer

Correct Answer: REpresentational State Transfer

Note: This Question is unanswered, help us to find answer for this one

160.

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?

Answer

Correct Answer: It is possible, but it is a bad idea because Views should only be responsible for displaying objects passed to them.

Note: This Question is unanswered, help us to find answer for this one

161.

What is the Singleton design pattern?

Answer

Correct Answer: A class for which there is only ever one instance.

Note: This Question is unanswered, help us to find answer for this one

162.

Which of the following statements is incorrect?

Answer

Correct Answer: Rails does not support ODBC connectivity.

Note: This Question is unanswered, help us to find answer for this one

163.

Which of the following serves as a structural skeleton for all HTML pages created?

Answer

Correct Answer: application.html.erb

Note: This Question is unanswered, help us to find answer for this one

164.

If a controller is named "Users", what would its helpers module be called?

Answer

Correct Answer: UsersHelper

Note: This Question is unanswered, help us to find answer for this one

165.

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>
</head>
<body></body>
</html>
Which of the following options is correct?

Answer

Correct Answer: The application will give an exception as @title variable is not defined in the controller.

Note: This Question is unanswered, help us to find answer for this one

166.

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?

Answer

Correct Answer: $ ruby -Itest test/unit/demo_test.rb -a test_one

Note: This Question is unanswered, help us to find answer for this one

167.

Which of the following will disable browser page caching in Rails?

Answer

Correct Answer: expire_page(:controller => 'products', :action => 'index')

Note: This Question is unanswered, help us to find answer for this one

168.

In a Rails Migration, which of the following will make a column unique, and then have it indexed?

Answer

Correct Answer: add_index :table_name, :column_name, :unique => true

Note: This Question is unanswered, help us to find answer for this one

169.

If a float is added to an integer, what is the class of the resulting number? i.e. 1.0 + 2

Answer

Correct Answer: Float

Note: This Question is unanswered, help us to find answer for this one

170.

In order to enable locking on a table, which of the following columns is added?

Answer

Correct Answer: lock_version column

Note: This Question is unanswered, help us to find answer for this one

171.

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();"
%>

Answer

Correct Answer: None of these

Note: This Question is unanswered, help us to find answer for this one

172.

Which of the following is the correct syntax for an input field of radio buttons in form_for?

Answer

Correct Answer: <%= f.radio_button :contactmethod, 'sms' %>

Note: This Question is unanswered, help us to find answer for this one

173.

Which of the following is the correct way to rollback a migration?

Answer

Correct Answer: rake db:rollback STEP=N (N is the migration number to be rollbacked)

Note: This Question is unanswered, help us to find answer for this one

174.

Which of the following methods is used to check whether an object is valid or invalid?

Answer

Correct Answer: .valid? and .invalid?

Note: This Question is unanswered, help us to find answer for this one

175.

What is the difference between :dependent => :destroy and :dependent => :delete_all in Rails?

Answer

Correct Answer: 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.

Note: This Question is unanswered, help us to find answer for this one

176.

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 meantime?

Answer

Correct Answer: rake db:rollback; rails destroy model Sales

Note: This Question is unanswered, help us to find answer for this one

177.

What is the output of the following code?
puts "aeiou".sub(/[aeiou]/, '*')

Answer

Correct Answer: *eiou

Note: This Question is unanswered, help us to find answer for this one

178.

What declaration would you use to set the layout for a controller?

Answer

Correct Answer: layout 'new_layout'

Note: This Question is unanswered, help us to find answer for this one

179.

Which of the following options, when passed as arguments, skips a particular validation?

Answer

Correct Answer: :validate => false

Note: This Question is unanswered, help us to find answer for this one

180.

Which of the following is the default way that Rails seeds data for tests?

Answer

Correct Answer: Fixtures

Note: This Question is unanswered, help us to find answer for this one

181.

Which of the following is the correct way to skip ActiveRecords in Rails 3?

Answer

Correct Answer: Add new line SKIP: ACTIVERECORD in config.generators.

Note: This Question is unanswered, help us to find answer for this one

182.

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_store :active_record_store
C) By setting config/initializers/session_store.rb with
Rails.application.config.session_store :active_record_store only

Answer

Correct Answer: B

Note: This Question is unanswered, help us to find answer for this one

183.

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" restarts the invocation of an iterator call. Also,
arguments to the iterator are re-evaluated.
Which of the following options is correct?

Answer

Correct Answer: Statement X is incorrect, but statement Y is correct.

Note: This Question is unanswered, help us to find answer for this one

184.

Which of the following commands will clear out sample users from the development database?

Answer

Correct Answer: rake db:reset

Note: This Question is unanswered, help us to find answer for this one

185.

Is an AJAX call synchronous or asynchronous?

Answer

Correct Answer: Either; it is configurable

Note: This Question is unanswered, help us to find answer for this one

186.

Which of the following assertions are used in testing views?

Answer

Correct Answer: assert_select_email

Note: This Question is unanswered, help us to find answer for this one

187.

What is green-threading?

Answer

Correct Answer: When threads are emulated by a virtual machine or interpreter.

Note: This Question is unanswered, help us to find answer for this one

188.

If a method #decoupage(n) is described as O(n^2), what does that mean?

Answer

Correct Answer: The worst case run time is proportional to the size of the square of the method's input.

Note: This Question is unanswered, help us to find answer for this one

189.

Which of the following replaced the Prototype JavaScript library in Ruby on Rails as the default JavaScript library?

Answer

Correct Answer: jQuery

Note: This Question is unanswered, help us to find answer for this one

190.

What component of Rails are tested with unit tests?

Answer

Correct Answer: Models

Note: This Question is unanswered, help us to find answer for this one

191.

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
..........

end

Answer

Correct Answer: All of these

Note: This Question is unanswered, help us to find answer for this one

192.

Which gem is used to install a debugger in Rails 3?

Answer

Correct Answer: gem "ruby-debug19"

Note: This Question is unanswered, help us to find answer for this one

193.

What is the output of the following code in Ruby?
x= "A" + "B"
puts x
y= "C" << "D"
puts y

Answer

Correct Answer: AB CD

Note: This Question is unanswered, help us to find answer for this one

194.

Which of the following items are stored in the models subdirectory?

Answer

Correct Answer: database classes

Note: This Question is unanswered, help us to find answer for this one

195.

Which part of the MVC stack does ERB or HAML typically participate in?

Answer

Correct Answer: View

Note: This Question is unanswered, help us to find answer for this one

196.

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 PartyAnimal
end

Answer

Correct Answer: PartyAnimal.party!

Note: This Question is unanswered, help us to find answer for this one

197.

where we use attr_accessor and attr_accessible in rails ?

Answer

Correct Answer: model

Note: This Question is unanswered, help us to find answer for this one

198.

What is the recommended Rails way to iterate over records for display in a view?

Answer

Correct Answer: Implicitly loop over a set of records, and send the partial being rendered a :collection.

Note: This Question is unanswered, help us to find answer for this one

199.

What is best way to create primary key as a string field instead of integer in rails.

Answer

Correct Answer: 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

Note: This Question is unanswered, help us to find answer for this one

200.

Which of the following is the correct way to know the Rails root directory path?

Answer

Correct Answer: Rails.root

Note: This Question is unanswered, help us to find answer for this one

201.

What is difference between "has_one" and "belong_to"?

Answer

Correct Answer: "belong_to" should be used in a model whose table have foreign keys while "has_one" is used with an associated table.

Note: This Question is unanswered, help us to find answer for this one

202.

What is the output of the following Ruby code?
puts "The multiplication output of 10,10,2 is #{10*10*2}"

Answer

Correct Answer: The multiplication output of 10,10,2 is 200.

Note: This Question is unanswered, help us to find answer for this one

203.

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
/api/v3/users returns a 301 to /api/v2/users
/api/asdf/users returns a 301 to /api/v2/users

Answer

Correct Answer: 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

Note: This Question is unanswered, help us to find answer for this one

204.

Which of the following code samples will get the index of |page| inside of a loop?

Answer

Correct Answer: <% @images.each_with_index do |page, index| %> <% end %>

Note: This Question is unanswered, help us to find answer for this one

205.

What is the difference between _url and _path while being used in routes?
 

Answer

Correct Answer: _url is absolute while _path is relative.

Note: This Question is unanswered, help us to find answer for this one

206.

When using full-page caching, what happens when an incoming request matches a page in the cache?

Answer

Correct Answer: Rails checks to see if there is a cached page on disk and passes it onto the server.

Note: This Question is unanswered, help us to find answer for this one

207.

What is the output of the following code?
test*5

Answer

Correct Answer: testtesttesttesttest

Note: This Question is unanswered, help us to find answer for this one

208.

In a has_many association, what is the difference between build and new?
// user.rb
has_many :posts
// post.rb
belongs_to :user

Answer

Correct Answer: 'build' sets the foreign key and adds it to the collection.

Note: This Question is unanswered, help us to find answer for this one

209.

Which of the following HTML template languages are supported by Ruby?

Answer

Correct Answer: Embedded Ruby

Note: This Question is unanswered, help us to find answer for this one

210.

Which of the following commands adds the data model info to the model file?

Answer

Correct Answer: generate model

Note: This Question is unanswered, help us to find answer for this one

211.

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)?

Answer

Correct Answer: Store it in a thread locally.

Note: This Question is unanswered, help us to find answer for this one

212.

In the case of Rails application performance optimization, select all valid ways to do assets compilation:

Answer

Correct Answer: All of these.

Note: This Question is unanswered, help us to find answer for this one

213.

Which of the following options in the Ruby on Rails MVC architecture handles the dynamic data and the classes with the database?

Answer

Correct Answer: Models

Note: This Question is unanswered, help us to find answer for this one

214.

With an XHTML document, how can quirks mode be triggered in Internet Explorer?

Answer

Correct Answer: Define a doc-type.

Note: This Question is unanswered, help us to find answer for this one

215.

Which of the following are Rails specific assertions to the test/unit framework?

Answer

Correct Answer: assert_no_difference

Note: This Question is unanswered, help us to find answer for this one

216.

Which of the following options will find a row from the Users table having id = 1?

Answer

Correct Answer: Users.find(1)

Note: This Question is unanswered, help us to find answer for this one

217. True or False? Proc is a nameless function, an anonymous method.

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

218. The 'rails c' command...

Answer

Correct Answer: Starts rails console

Note: This Question is unanswered, help us to find answer for this one

219. How to print the list of available generators?

Answer

Correct Answer: rails generate

Note: This Question is unanswered, help us to find answer for this one

220. After importing from GitHub our Ruby on Rails project via the terminal using "git clone ...", what is required to do to ensure we can start working on our project?

Answer

Correct Answer: Navigate to our project folder, bundle install, rake db:create, rake db:migrate

Note: This Question is unanswered, help us to find answer for this one

221. What is the right command to see the list of available tasks?

Answer

Correct Answer: rake -T or rake --tasks

Note: This Question is unanswered, help us to find answer for this one

222. Let we have declared a Student class. What is output of this statement? Student.class

Answer

Correct Answer: Object

Note: This Question is unanswered, help us to find answer for this one

223. Which of these statements will utilize the gem named 'mygem

Answer

Correct Answer: require 'mygem'

Note: This Question is unanswered, help us to find answer for this one

224. Where to add business logic? a) Model b) Controller c) View

Answer

Correct Answer: a

Note: This Question is unanswered, help us to find answer for this one

225. Where declare validations to a application?

Answer

Correct Answer: Model

Note: This Question is unanswered, help us to find answer for this one

226. If @user is not null, the expression <%= @user.present? ? "Yes" : "No" %> return:

Answer

Correct Answer: Yes

Note: This Question is unanswered, help us to find answer for this one

227. What is the difference between Post.find(3) and Post.find_by_id(3) ?

Answer

Correct Answer: find_by will not throw the exception if post with an id=3 will not be found

Note: This Question is unanswered, help us to find answer for this one

228. a = (1..3).reduce(-6){ |i,x| x + i } puts a

Answer

Correct Answer: 0

Note: This Question is unanswered, help us to find answer for this one

229. [1,2,3,5,8,13].include? '8'

Answer

Correct Answer: false

Note: This Question is unanswered, help us to find answer for this one

230. The databases supported by ActiveRecord without any other gem are:

Answer

Correct Answer: Sqlite, MySQL, PostgreSQL

Note: This Question is unanswered, help us to find answer for this one

231. What is the purpose of config.ru file?

Answer

Correct Answer: It's the Rack configuration file, a module webserver interface

Note: This Question is unanswered, help us to find answer for this one

232. The best practice says:

Answer

Correct Answer: Fat models, thin controllers and views

Note: This Question is unanswered, help us to find answer for this one

233. How you can load your database with seeded data

Answer

Correct Answer: rake db:seed

Note: This Question is unanswered, help us to find answer for this one

234. How to add a coffeescript file, follow the Asset Pipeline rules, somewhere in the "view"?

Answer

Correct Answer: <%= javascript_include_tag "javascript-file-name" %>

Note: This Question is unanswered, help us to find answer for this one

235. Where you define the gems used in a Ruby on Rails application?

Answer

Correct Answer: Gemfile

Note: This Question is unanswered, help us to find answer for this one

236. I already have a project running locally on port 3000. How can I start another project on port 3001?

Answer

Correct Answer: rails s -p 3001

Note: This Question is unanswered, help us to find answer for this one

237. True or False. Using "rails g scaffold card", this will create a Card controller, model and views.

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

238. What is the output of following? 1==(0||1)

Answer

Correct Answer: false

Note: This Question is unanswered, help us to find answer for this one

239. Which of the following is not a standard validates option?

Answer

Correct Answer: :unique

Note: This Question is unanswered, help us to find answer for this one

240. The index_by method is...

Answer

Correct Answer: a Ruby on Rails method to create a Hash from an Array with keys computed by the block argument

Note: This Question is unanswered, help us to find answer for this one

241. Which of the following will return true?

Answer

Correct Answer: false.class.superclass == Object

Note: This Question is unanswered, help us to find answer for this one

242. Initialize method is always:

Answer

Correct Answer: private

Note: This Question is unanswered, help us to find answer for this one

243. how Date.today differs from Date.current?

Answer

Correct Answer: with Date.today you’ll have a system date

Note: This Question is unanswered, help us to find answer for this one

244. What is Strong Parameters in rails 4 ?

Answer

Correct Answer: It provides an interface for protecting attributes from end-user assignment.

Note: This Question is unanswered, help us to find answer for this one

245. To establish an association from a Post model to another Post model (say if one post is in response to another and there is a parent_post_id column on the posts table), you would add the following to the Post model:

Answer

Correct Answer: belongs_to :parent_post, :class_name => 'Post'

Note: This Question is unanswered, help us to find answer for this one

246. What is the output of the following? a = (1 <=> 2) b = (1 <=> 1.0) c = (b <=> a) puts c

Answer

Correct Answer: 1

Note: This Question is unanswered, help us to find answer for this one

247. Which of the following is a built-in feature of ActiveRecord

Answer

Correct Answer: Enums

Note: This Question is unanswered, help us to find answer for this one

248. We have given: str = 'abcdef' Which of the following will return the string 'def'? 1) str[0,-3] 2) str[-3,3] 3) str[4,3] 4) str['def']

Answer

Correct Answer: 2 and 4

Note: This Question is unanswered, help us to find answer for this one

249. Which of the following are NOT Ruby keywords? 1) alias 2) yield 3) defined? 4) include?

Answer

Correct Answer: 4

Note: This Question is unanswered, help us to find answer for this one

250. Which of the following will return false?

Answer

Correct Answer: (1...5) === 5

Note: This Question is unanswered, help us to find answer for this one

251. Choose the correct result p a = 1, a = 2

Answer

Correct Answer: 1 //line break// 2

Note: This Question is unanswered, help us to find answer for this one

252. Which one IS NOT an application server:

Answer

Correct Answer: Tomahawk

Note: This Question is unanswered, help us to find answer for this one

253. Given the following code: ; module Wheeled; end ; class Vehicle; end ; class Car < Vehicle ; include Wheeled ; end ; What is the value of this expression: Car.new.kind_of? Wheeled

Answer

Correct Answer: true

Note: This Question is unanswered, help us to find answer for this one

254. If your controller gets an action that it will render a template for, and you need to add a flash notice to the page, you'd use:

Answer

Correct Answer: flash.now[:notice] = notice_message

Note: This Question is unanswered, help us to find answer for this one

255. Output of the following ? person1 = 'Tim' person2 = person1 person1[0] = 'J' puts person1 puts person2

Answer

Correct Answer: Jim Jim

Note: This Question is unanswered, help us to find answer for this one

256. You've got a form, and when the user submits invalid data, you simply show them an error page (no redirect). In the controller, to show the general error on the rendered page, you would add:

Answer

Correct Answer: In controller: flash.now[:error] = message

Note: This Question is unanswered, help us to find answer for this one

257. Counter caches can be used for:

Answer

Correct Answer: Caching the counts of associations to avoid unnecessary Model.count queries

Note: This Question is unanswered, help us to find answer for this one

258. Handling an AJAX request in controller, which of the following redirects to google?

Answer

Correct Answer: render js: "window.location = 'http://google.com'"

Note: This Question is unanswered, help us to find answer for this one

259. If you're using the standard Rails RESTful routes, then which of the following actions map to the url, '/posts'?

Answer

Correct Answer: posts#create or posts#index

Note: This Question is unanswered, help us to find answer for this one

260. In development mode (config.assets.digest = false), if a file exists in app/assets/javascript/hello.js, which link will show that file ?

Answer

Correct Answer: localhost:3000/assets/hello.js

Note: This Question is unanswered, help us to find answer for this one

261. Determine the value of the variable a, b and c after the execution of the following code. a, b, c = 1, 2, 3, 4

Answer

Correct Answer: a = 1 b = 2 c = 3

Note: This Question is unanswered, help us to find answer for this one

262. Which is not a valid callback?

Answer

Correct Answer: after_delete

Note: This Question is unanswered, help us to find answer for this one

263. In The Author Model, how do you create a nested association between Authors and Blogs?

Answer

Correct Answer: has_many :blogs

Note: This Question is unanswered, help us to find answer for this one

264. What's an equivalent way of performing the following (h is a Hash): h.each { |k,v| h.delete k if k.nil? }

Answer

Correct Answer: h.delete_if { |k,v| k.nil? }

Note: This Question is unanswered, help us to find answer for this one

265. Which of the following are valid objects of class Integer or one of its subclasses? 1) -123 2) 0xFF 3) 123_456_789 4) 123456789123456789123456789123456789

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

266. If a method is protected:

Answer

Correct Answer: It may be called by any instance of the defining class or its subclasses

Note: This Question is unanswered, help us to find answer for this one

267. The Controller in Post#create: what is the "best practice" action when the user submits an invalid form?

Answer

Correct Answer: render action: 'new', alert: 'The Post is incomplete or invalid.'

Note: This Question is unanswered, help us to find answer for this one

268. Which HTTP method is used by default when clicking a button defined using the ActionView helper method 'button_to'?

Answer

Correct Answer: post

Note: This Question is unanswered, help us to find answer for this one

269. What is the ActionView form helper tag for

Answer

Correct Answer: <%= text_field_tag

Note: This Question is unanswered, help us to find answer for this one

270. Procs are objects, Blocks are not.

Answer

Correct Answer: true

Note: This Question is unanswered, help us to find answer for this one

271. Which of the following associations does NOT declare a many-to-many relationship?

Answer

Correct Answer: has_many

Note: This Question is unanswered, help us to find answer for this one

272. If the class User has a belongs_to :role, which table has the foreign key?

Answer

Correct Answer: User

Note: This Question is unanswered, help us to find answer for this one

273. For your app to route the "http://myapp.com/" to the home controller, index action; what could you add to your routes.rb file?

Answer

Correct Answer: root :to =>

Note: This Question is unanswered, help us to find answer for this one

274. What is the best practice to implement translations of the title of a component in the view using i18n API?

Answer

Correct Answer: I18n.t('component.title')

Note: This Question is unanswered, help us to find answer for this one

275. What does Model.reset_column_information do?

Answer

Correct Answer: Resets all the cached information about columns.

Note: This Question is unanswered, help us to find answer for this one

276. What kind of variables are Author and AUTHOR?

Answer

Correct Answer: constant

Note: This Question is unanswered, help us to find answer for this one

277. How do you render a variable in ERB template?

Answer

Correct Answer: <%= variable_name =>

Note: This Question is unanswered, help us to find answer for this one

278. How does the Asset Pipeline (Rails 3.1 +) deal with different precompiled versions of an asset?

Answer

Correct Answer: Append MD5 digest to filename at precompile

Note: This Question is unanswered, help us to find answer for this one

279. What is not a proper REST verb?

Answer

Correct Answer: update

Note: This Question is unanswered, help us to find answer for this one

280. What is the proper way to subclass a Module?

Answer

Correct Answer: You cannot subclass a Module.

Note: This Question is unanswered, help us to find answer for this one

281. Which expression will not return a sum of array elements in Ruby on Rails?

Answer

Correct Answer: None of them. All will return the sum.

Note: This Question is unanswered, help us to find answer for this one

282. Which column type is NOT supported by Active Record?

Answer

Correct Answer: blob

Note: This Question is unanswered, help us to find answer for this one

283. Which of these code blocks cannot be right?

Answer

Correct Answer: = form_for User do |f|

Note: This Question is unanswered, help us to find answer for this one

284. What is the output of the following? $x = 10 puts defined? $X

Answer

Correct Answer: nil

Note: This Question is unanswered, help us to find answer for this one

285. When you've got a form, and when the user submits invalid data, you redirect back to the edit form. If you want to show a general error message (not tied to validation errors) to the user, you'd do which of the following?

Answer

Correct Answer: In controller: flash[:error] = message

Note: This Question is unanswered, help us to find answer for this one

286. Which of these is NOT a valid way of associating models?

Answer

Correct Answer: has_and_belongs_to

Note: This Question is unanswered, help us to find answer for this one

287. To randomize the order of entries in an Array, use the _______ method.

Answer

Correct Answer: shuffle

Note: This Question is unanswered, help us to find answer for this one

288. What is the output of the following? puts 'a\nb'

Answer

Correct Answer: a\nb

Note: This Question is unanswered, help us to find answer for this one

289. Which of the following controller methods is NOT properly paired with its HTTP counterpart?

Answer

Correct Answer: SHOW for PUT

Note: This Question is unanswered, help us to find answer for this one

290. What is the main function of helpers used in Ruby on Rails?

Answer

Correct Answer: Helpers are the functionality provided by the View for the modules to provide the help classes in MVC architecture.

Note: This Question is unanswered, help us to find answer for this one

291. Functional tests are used to test what part of a Rails application?

Answer

Correct Answer: Controllers

Note: This Question is unanswered, help us to find answer for this one

292. Which of the following is a correctly formatted multi-line comment?

Answer

Correct Answer: =begin COMMENT =end

Note: This Question is unanswered, help us to find answer for this one

293. The session is, by default, accessible to:

Answer

Correct Answer: controllers and views

Note: This Question is unanswered, help us to find answer for this one

294. Does RoR supports multiple inheritance?

Answer

Correct Answer: false

Note: This Question is unanswered, help us to find answer for this one

295. String objects are _______.

Answer

Correct Answer: Mutable

Note: This Question is unanswered, help us to find answer for this one

296. A class variable (not class level instance variable) has a name beginning with ___________.

Answer

Correct Answer: @@

Note: This Question is unanswered, help us to find answer for this one

297. Ruby supports single inheritance, multiple inheritance, or both?

Answer

Correct Answer: Single Inheritance

Note: This Question is unanswered, help us to find answer for this one

298. Which is NOT an ActiveRecord migration method?

Answer

Correct Answer: add_key

Note: This Question is unanswered, help us to find answer for this one

299. A correct example of class inheritance from "Exception" into "Bomber"

Answer

Correct Answer: class Bomber < Exception def initialize # Instance end end

Note: This Question is unanswered, help us to find answer for this one

300. When rendering a partial on a collection, what is the recommended method?

Answer

Correct Answer: <%= render :partial => 'partial_to_render', :collection => @collection %>

Note: This Question is unanswered, help us to find answer for this one

301. In a Rails migration, what's the syntax for creating a table?

Answer

Correct Answer: create_table :table_name

Note: This Question is unanswered, help us to find answer for this one

302. Ruby 1.9, what new method of building key-value pairs is supported?

Answer

Correct Answer: :

Note: This Question is unanswered, help us to find answer for this one

303. Which of these is not a valid form helper?

Answer

Correct Answer: text_box

Note: This Question is unanswered, help us to find answer for this one

304. What is the output of the following? @@x = 10 puts defined? @@x

Answer

Correct Answer: class variable

Note: This Question is unanswered, help us to find answer for this one

305. In the context of unit testing Rails applications, "fixture" refers to which of the following?

Answer

Correct Answer: Predefined data for populating the testing database

Note: This Question is unanswered, help us to find answer for this one

306. Which does NOT append "nine" to the array: "big_data"?

Answer

Correct Answer: big_data.append("nine")

Note: This Question is unanswered, help us to find answer for this one

307. If you want to display the price of an item, with a :time_span tag, where would you place this code?

Answer

Correct Answer: helper_function or view

Note: This Question is unanswered, help us to find answer for this one

308. What is the main step to add ajax call in Ruby on Rails?

Answer

Correct Answer: remote: true

Note: This Question is unanswered, help us to find answer for this one

309. Which command would generate a DogController with a 'bark' action?

Answer

Correct Answer: rails g controller Dog bark

Note: This Question is unanswered, help us to find answer for this one

310. Which is an incorrectly defined method?

Answer

Correct Answer: def method_name() # method operations

Note: This Question is unanswered, help us to find answer for this one

311. Unit tests are used to test what part of a Rails application?

Answer

Correct Answer: Models

Note: This Question is unanswered, help us to find answer for this one

312. Where do you add named scopes?

Answer

Correct Answer: Models

Note: This Question is unanswered, help us to find answer for this one

313. What is not a RESTful controller action?

Answer

Correct Answer: insert

Note: This Question is unanswered, help us to find answer for this one

314. What is the output for the following? x = 1==1 ? "a" : "b"; puts x

Answer

Correct Answer: a

Note: This Question is unanswered, help us to find answer for this one

315. Which is NOT a reserved Ruby logic flow word?

Answer

Correct Answer: elseif

Note: This Question is unanswered, help us to find answer for this one

316. Of the following, which would create a new project without unit test?

Answer

Correct Answer: $ rails new example_app -T

Note: This Question is unanswered, help us to find answer for this one

317. How would you check to see if an array named COLORS contains the the value 'red'?

Answer

Correct Answer: COLORS.include?('red')

Note: This Question is unanswered, help us to find answer for this one

318. Which of these is NOT a default subdirectory of the app/ directory?

Answer

Correct Answer: environments

Note: This Question is unanswered, help us to find answer for this one

319. If you have posts and each post has_many comments, how do you structure your routes?

Answer

Correct Answer: resources :posts do resources :comments end

Note: This Question is unanswered, help us to find answer for this one

320. Which is NOT an ActiveRecord query method?

Answer

Correct Answer: has

Note: This Question is unanswered, help us to find answer for this one

321. Which of the following will check the array named "big_data" for the presence of a key "icecream"?

Answer

Correct Answer: big_data.has_key?("icecream")

Note: This Question is unanswered, help us to find answer for this one

322. If you create PostsController, where will Rails look for its templates by default?

Answer

Correct Answer: app/views/posts

Note: This Question is unanswered, help us to find answer for this one

323. How do you remove a column during a migration?

Answer

Correct Answer: remove_column :table_name, :column_name

Note: This Question is unanswered, help us to find answer for this one

324. Which command, when run, will compile all assets in the 'app/assets' directory and copy compiled versions to a configured target directory ('public/assets' by default)?

Answer

Correct Answer: rake assets:precompile

Note: This Question is unanswered, help us to find answer for this one

325. Which is NOT a Ruby operator?

Answer

Correct Answer: =!

Note: This Question is unanswered, help us to find answer for this one

326. What is the most elegant way to include a javascript file needed for only one page?

Answer

Correct Answer: <%= javascript_include_tag

Note: This Question is unanswered, help us to find answer for this one

327. belongs_to: Represents the inverse of a has_one (or has_many) association.

Answer

Correct Answer: true

Note: This Question is unanswered, help us to find answer for this one

328. What is the difference between Symbol and String?

Answer

Correct Answer: symbols, belongs to the category of immutable

Note: This Question is unanswered, help us to find answer for this one

329. If you want the standard restful routes for your person controller, how do you add that?

Answer

Correct Answer: resources :people

Note: This Question is unanswered, help us to find answer for this one

330. Where will routes.rb file appear?

Answer

Correct Answer: config/routes.rb

Note: This Question is unanswered, help us to find answer for this one

331. A module cannot be subclassed or instantiated.

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

332. Which of the following is a working ruby while-loop?

Answer

Correct Answer: while i < 100 do # DO THINGS i += 1 end

Note: This Question is unanswered, help us to find answer for this one

333. What part of a migration runs during a rollback?

Answer

Correct Answer: self.down

Note: This Question is unanswered, help us to find answer for this one

334. Which is NOT a model validation method?

Answer

Correct Answer: validates_form_of

Note: This Question is unanswered, help us to find answer for this one

335. which one is class method?

Answer

Correct Answer: class A def self.a end end

Note: This Question is unanswered, help us to find answer for this one

336. If you want to append an item to an array, what is the standard method?

Answer

Correct Answer: arr << item

Note: This Question is unanswered, help us to find answer for this one

337. Determine the value of the variable x after the execution of the following code. x = [1,2,3] x.pop until x.empty? x.push(4) while x.empty?

Answer

Correct Answer: [4]

Note: This Question is unanswered, help us to find answer for this one

338. What file will rails look for given the following erb: <%= render 'some_partial' %>?

Answer

Correct Answer: _some_partial.html.erb

Note: This Question is unanswered, help us to find answer for this one

339. Imagine that you have two models: "User" and "Book", and a user can have only one book. How should the association look like in the "User" model?

Answer

Correct Answer: has_one :book

Note: This Question is unanswered, help us to find answer for this one

340. What is the use of @ in Ruby?

Answer

Correct Answer: instance variable

Note: This Question is unanswered, help us to find answer for this one

341. Which of these javascript frameworks became the default with the release of Rails 3.1?

Answer

Correct Answer: jQuery

Note: This Question is unanswered, help us to find answer for this one

342. What is the use of the 'defined?' method?

Answer

Correct Answer: To determine if the variable is defined at the current scope

Note: This Question is unanswered, help us to find answer for this one

343. If you want the /person url to map to your dog controller and show method, what do you add to your routes?

Answer

Correct Answer: match '/person', :to => 'dog#show'

Note: This Question is unanswered, help us to find answer for this one

344. Which of these does NOT correctly return the version of Ruby?

Answer

Correct Answer: -VERSION

Note: This Question is unanswered, help us to find answer for this one

345. How do you create a new user object with the name david and save it to the database?

Answer

Correct Answer: User.create(:name => 'david')

Note: This Question is unanswered, help us to find answer for this one

346. Which of the following prints the "Hello WORLD!" output with a new line?

Answer

Correct Answer: puts "Hello WORLD!"

Note: This Question is unanswered, help us to find answer for this one

347. is it possible to change the default port when running a rails server ?

Answer

Correct Answer: yes

Note: This Question is unanswered, help us to find answer for this one

348. What is the default value for a global variable (before initialization)?

Answer

Correct Answer: nil

Note: This Question is unanswered, help us to find answer for this one

349. Which files is used to specify any default data that should be loaded into the application's database, when it is first setup?

Answer

Correct Answer: db/seeds.rb

Note: This Question is unanswered, help us to find answer for this one

350. The recommended directory in which to place your app's javascript files is:

Answer

Correct Answer: app/assets/javascripts

Note: This Question is unanswered, help us to find answer for this one

351. Which of these is not a standard directory in a Rails application?

Answer

Correct Answer: All of these are standard directories

Note: This Question is unanswered, help us to find answer for this one

352. What is a typical file extension found in the app/controllers directory

Answer

Correct Answer: .rb

Note: This Question is unanswered, help us to find answer for this one

353. What ORM does Ruby on Rails use by default?

Answer

Correct Answer: ActiveRecord

Note: This Question is unanswered, help us to find answer for this one

354. What is the output of the following ? s="foo" * 2 puts s

Answer

Correct Answer: foofoo

Note: This Question is unanswered, help us to find answer for this one

355. Which of the following will interpolate within a string with the variable named 'monster'?

Answer

Correct Answer: "#{monster}"

Note: This Question is unanswered, help us to find answer for this one

356. What is the preferred method of validating that the name has been set?

Answer

Correct Answer: validates :name, :presence => true

Note: This Question is unanswered, help us to find answer for this one

357. Migrations...

Answer

Correct Answer: modify a database by adding or removing columns or tables.

Note: This Question is unanswered, help us to find answer for this one

358. What command do you run to update your database?

Answer

Correct Answer: rake db:migrate

Note: This Question is unanswered, help us to find answer for this one

359. Ruby uses:

Answer

Correct Answer: nil

Note: This Question is unanswered, help us to find answer for this one

360. How would you declare an Instance Variable?

Answer

Correct Answer: @

Note: This Question is unanswered, help us to find answer for this one

361. What command do you run to drop your database?

Answer

Correct Answer: rake db:drop

Note: This Question is unanswered, help us to find answer for this one

362. What command do you run to create your database?

Answer

Correct Answer: rake db:create

Note: This Question is unanswered, help us to find answer for this one

363. What is the command to install Rails?

Answer

Correct Answer: gem install rails

Note: This Question is unanswered, help us to find answer for this one

364. In the MVC pattern:

Answer

Correct Answer: models represent the data, views display the data, and controllers respond to user interactions

Note: This Question is unanswered, help us to find answer for this one

365. Which extension is default for views html templates?

Answer

Correct Answer: .erb

Note: This Question is unanswered, help us to find answer for this one

366. What is a Gem?

Answer

Correct Answer: Functionality in a package

Note: This Question is unanswered, help us to find answer for this one

367. Which is NOT a default Rails environment?

Answer

Correct Answer: sandbox

Note: This Question is unanswered, help us to find answer for this one

368. What is the use of @@ in Ruby?

Answer

Correct Answer: class variable

Note: This Question is unanswered, help us to find answer for this one

369. What is the use of $ in Ruby?

Answer

Correct Answer: $ in Ruby is treated as a global variable

Note: This Question is unanswered, help us to find answer for this one

370. Which of the following will delete the key-value 1 from array: "big_data"?

Answer

Correct Answer: big_data.delete(1)

Note: This Question is unanswered, help us to find answer for this one

371. How can you create a new Rails project?

Answer

Correct Answer: 'rails new /path/to/new/app'

Note: This Question is unanswered, help us to find answer for this one

372. What gets returned by: [1, [2, 3,[4, 5]]].flatten

Answer

Correct Answer: [1, 2, 3, 4, 5]

Note: This Question is unanswered, help us to find answer for this one

373. A global variable has a name beginning with:

Answer

Correct Answer: $

Note: This Question is unanswered, help us to find answer for this one

374. What command do you run to undo the last 5 migrations

Answer

Correct Answer: rake db:rollback STEP=5

Note: This Question is unanswered, help us to find answer for this one