Ruby on Rails/Ruby on Rails Multiple choice Questions Set 3 Sample Test,Sample questions

Question:
A global variable has a name beginning with:

1.$

2.%

3.@

4.@@


Question:
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?

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

2.BlogPost.where(['comments.created_at', @range])

3.BlogPost.preload (

4.BlogPost.includes (:comments).where('comments.created_at' => @range)


Question:
How can you create a new Rails project?

1.'rails new /path/to/new/app'

2. 'rails /path/to/new/app'

3. 'rails create /path/to/new/app'

4.None of the above


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

1.User.build(:name => 'david')

2.User.create(:name => 'david')

3.User.new(:name => 'david')

4. User.make(:name => 'david')


Question:
How would you declare an Instance Variable?

1.@@

2.@

3.both (a) and (b)

4.None of these


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

1.User.where(last_name: 'Smith')

2.User.find_or_create(last_name: 'Smith')

3.User.find_by_last_name('Smith')

4.User.find('Smith')


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

1.match '/person', :to => 'dog#show'

2.map.resources :person

3.map.resources :dog

4.map.resources :person => :dog


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

1.It filters out all parameters.

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

3.It raises an error if parameters that are not named :name or :sku are found.

4.It raises an error if the :name and :sku parameters are set to nil.


Question:
In the MVC pattern:

1.MVC are the initials of the creator, Michael Vincent Clantor.

2.mySQL is the database, vi is the text editor, and C++ is the language.

3.models represent the data, views display the data, and controllers respond to user interactions

4.manipulators handle data, validators ensure data integrity, and communicators transfer information between them.


Question:
Migrations...

1.generally affect only views and sometimes controllers.

2.can never be reversed.

3.back up a project by copying it to another location.

4.modify a database by adding or removing columns or tables.


Question:
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}

1.=>

2.<==>

3.<=>

4.||


Question:
Ruby uses:

1.null

2.nil

3.both (a) and (b)

4.None of these


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

1.app/assets/javascripts

2.app/javascripts

3.assets/javascripts

4. public/javascripts


Question:
What command do you run to create your database?

1.database_create

2.rake db:migrate

3. rake db:create

4. rails create


Question:
What command do you run to drop your database?

1.rails destroy

2.rake db:drop

3.rake db:migrate

4.database_drop


Question:
What command do you run to undo the last 5 migrations

1.rake db:rollback STEP=5

2.database_undo

3. rake db:drop

4.rake db:rollback


Question:
What command do you run to update your database?

1.database_update

2.rake db:migrate

3.rails update

4. rake db:rollback


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

1.[1, 2, 3, 4, 5]

2.[1, [2, 3, 4, 5]]

3.[2, 3, [4, 5]

4.] [1, 2, 3, [4, 5]]


Question:
What is a Gem?

1.A configuration item

2. Functionality in a package

3.both (a) and (b)

4.None of the above


Question:
What is a typical file extension found in the app/controllers directory

1..yml . .

2.erb

3..rb

4.html.


Question:
What is the command to install Rails?

1.gem install ruby_on_rails

2.gem install ror

3.gem install rails

4.None of the above


Question:
What is the default value for a global variable (before initialization)?

1.null

2.nil

3.0

4.nul


Question:
What is the output of the following ? s="foo" * 2 puts s

1.foo*2

2.foofoo

3.Gives an Error

4.foo


Question:
What is the preferred method of validating that the name has been set?

1.validates :name, :presence => true

2.save!

3.before_save if name != nil return true end return false end

4.validates :name => not_null


Question:
What is the use of $ in Ruby?

1.$ in Ruby is treated as a class variable

2.$ in Ruby is treated as a global variable

3.both (a) and (b)

4.None of the above


Question:
What is the use of the 'defined?' method?

1.To find the value of a variable

2.To find the memory allocated to that variable

3.To determine if the variable is defined at the current scope

4.To find whether it is a constant or variable


Question:
What ORM does Ruby on Rails use by default?

1.ActiveRails

2.ActiveSupport

3.SQL

4.ActiveRecord


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

1.The method executes using

2.Any ending line return will be omitted from the result.

3.The method will ignore exceptions that occur during execution.

4.It is a more powerful or destructive version of the method.


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

1.Either true or false

2.An unsaved Tag instance

3.A saved Tag instance

4.An array of Tag instances


Question:
Which choice is an incorrect way to render a partial?

1.<%= render(:partial => 'shared/product') %>

2.<%= render('shared/product', :collection => @products) %>

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

4.<%= render('shared/product', locals: { product: @product }) %>


Question:
Which choice is not a valid Rails route?

1.Route

2.Match

3.Root

4.Get


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

1.Before_action :login_required, skip: [:get_posts]

2.Skip_before_action :login_required, except: [:get_posts]

3.Skip_before_action :login_required, only: [:get_posts]

4.Skip_action before: :login_required, only: [:get_posts


Question:
Which extension is default for views html templates?

1..erb . ..

2.slim

3.rabl

4.haml


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

1.db/default_data.rb

2.db/migrate/inital_load.rb

3.db/migrate/default_data.rb

4. db/seeds.rb


Question:
Which is NOT a default Rails environment?

1.sandbox

2.test

3.development

4.production


Question:
Which of the following prints the "Hello WORLD!" output with a new line?

1.puts "Hello WORLD!"

2.print "Hello WORLD!"

3.disp( "Hello WORLD!" )

4.None of the above


Question:
Which of the following will delete the key-value 1 from array: "big_data"

1.big_data.del(1)

2.big_data.del[1]

3.big_data.delete(1)

4.None of these


Question:
Which of the following will interpolate within a string with the variable named 'monster'?

1."/monster"

2."#{monster}"

3.{monster}

4."{monster}"


Question:
Which of these does NOT correctly return the version of Ruby?

1.-VERSION

2.--version

3.-v

4.None of the above


Question:
Which of these is not a standard directory in a Rails application?

1.db

2.lib

3.app

4.All of these are standard directories


Question:
Which of these javascript frameworks became the default with the release of Rails 3.1?

1.rails.js

2.jQuery

3.rails-script

4.Prototype


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

1.View

2.Controller

3.ActiveRecord

4.Model


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

1.Csrf_protection

2.Csrf_helper

3.Csrf_meta_tags

4.Csrf


Question:
Which statement about ActiveRecord models is true?

1.Each database column requres adding a matching attr_accessor declaration in the ActiveRecord model.

2.All attributes in an ActiveRecord model are read-only declared as writable using attr_accessible

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

4.ActiveRecord models can have only attributes that have a matching database column


More MCQS

  1. Ruby MCQ Questions
  2. Ruby on Rails Multiple choice Questions Set 1
  3. Ruby on Rails Multiple choice Questions Set 2
  4. Ruby on Rails Multiple choice Questions Set 3
  5. Ruby on Rails MCQ
Search
Olete Team
Online Exam TestTop Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on Online Exam Testwebsite is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!