Rubi on Rails MCQ: Rubi on Rails Multiple Choice Questions

Rubi on Rails MCQ  with answers and explanations for placement tests and job interviews. These solved Rubi on Rails MCQs are useful for the campus placement for all freshers including Engineering Students, MCA students, Computer and IT Engineers, etc.

Our Rubi on Rails MCQ (Rubi on Rails Multiple Choice Questions ) focuses on various parts of the Rubi on Rails web application framework and its concept. It will be useful for anyone learning Rubi on Rails Basics, Essentials, and/or Fundamentals. We will regularly update the quiz and most interesting thing is that questions come in a random sequence. So every time you will feel new questions.

You may have come across several Rubi on Rails courses during your search for learning the Rubi on Rails language. Our team of experts has carefully analyzed some Rubi on Rails courses for you. You can check the courses, Trial of some courses is free.

 

Guideline of Rubi on Rails MCQ:

This Rubi on Rails MCQ is intended for checking your Rubi on Rails web application framework knowledge. It takes 1 hour to pass the Rubi on Rails MCQ. If you don’t finish the Rubi on Rails MCQ within the mentioned time, all the unanswered questions will count as wrong. You can miss the questions by clicking the “Next” button and return to the previous questions by the “Previous” button. Every unanswered question will count as wrong. MCQ on Rubi on Rails has features of randomization which feel you a new question set at every attempt.

In this Rubi on Rails MCQ, we have also implemented a feature that not allowed the user to see the next question or finish the Rubi on Rail’s quiz without attempting the current Rubi on Rails MCQ.

1 votes, 5 avg

You have 1 hours to take the Rubi on Rails MCQs

Your time has been Over.


Rubi on Rails MCQ

Rubi on Rails MCQ: Rubi on Rails Multiple Choice Questions and Answers

1 / 48

What is the reason for using Concerns in Rails?

2 / 48

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

3 / 48

If a database table of users contains the following rows, and id is the primary key, which statement would return only an object whose last_name is "Cordero"?

-------------------------------

| id | first_name | last_name |
|----|------------|-----------|
| 1  | Alice      | Anderson  |
| 2  | Bob        | Buckner   |
| 3  | Carrie     | Cordero   |
| 4  | Devon      | Dupre     |
| 5  | Carrie     | Eastman   |

-------------------------------

 

4 / 48

Which choice best describes the expected value of @result?

@result = Article.first.tags.build(name: 'Urgent')

 

5 / 48

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

6 / 48

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

7 / 48

Given this code, which statement about the database table "documents" could be expected to be true?

class Document < ActiveRecord::Base
  belongs_to :documentable, polymorphic: true
end

class Product < ActiveRecord::Base
  has_many :documents, as: :documentable
end

class Service < ActiveRecord::Base
  has_many :documents, as: :documentable
end

 

8 / 48

Given this controller code, which choice describes the expected behavior if parameters are submitted to the update action that includes values for the product's name, style, color, and price?

class ProductController < ActionController::Base

  def update
    @product = Product.find(params[:id])
    if @product.update_attributes(product_params)
      redirect_to(product_path(@product))
    else
      render('edit')
    end
  end

  private

  def product_params
    params.require(:product).permit(:name, :style, :color)
  end
end

 

9 / 48

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

10 / 48

In Rails, what caching stores can be used?

11 / 48

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

12 / 48

Which statment about ActiveRecord models is true?

13 / 48

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?

14 / 48

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?

15 / 48

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

16 / 48

Which ActiveRecord query prevents SQL injection?

17 / 48

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

18 / 48

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

19 / 48

Which choice includes standard REST HTTP verbs?

20 / 48

What is the correct way to assign a value to the session?

1. 

$_SESSION['user_id'] = user.id

2. 

@session ||= Session.new << user.id

3. 

session_save(:user_id, user.id)

4. 

session[:user_id] = user.id

21 / 48

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

22 / 48

What part of the code below causes the method #decrypt_data to be run?

class MyModel < ApplicationRecord
after_find :decrypt_data
end

 

23 / 48

Which HTML is closes to what this code would output?

<% check_box(:post, :visible) %>

1. 

<input type="hidden" name="post[visible]" value="0" />
<input type="checkbox" name="post[visible]" value="1" />

2. 

<checkbox name="post[visible]" value="1" />

3. 

<input type="checkbox" name="post[visible]" value="1" data-default-value="0" />

4. 

<input type="checkbox" name="post[visible]" value="1" />

24 / 48

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

25 / 48

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

26 / 48

If a product has a user-uploadable photo, which ActiveStorage method should fill in the blank?

class Product << ApplicationRecord
  ____ :photo
end

 

27 / 48

How would you validate that a project's name is not blank, is fewer than 50 characters, and is unique?

1. 

class Project
  validates :name, presence: true, length: { maximum: 50 }, uniqueness: true
end

2. 

class Project
  validate_attribute :name, [:presence, :uniqueness], :length => 1..50
end

3. 

class Project
  validate_before_save :name, [:presence, [:length, 50], :uniqueness], :length => 1..50
end

4.

class Project
  validates_presense_of :name, :unique => true
  validates_length_of :name, :maximum => 50
end

 

 

28 / 48

Which ActiveRecord query prevents SQL injection?

29 / 48

 There is a bug in this code. The logout message is not appearing on the login template. What is the cause?

class AccessController < ActionController::Base
  def destroy
    session[:admin_id] = nil
    flash[:notice] = ""You have been logged out""
    render('login')
end

 

30 / 48

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

31 / 48

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

32 / 48

A Rails project has ActiveRecord classes defined for Classroom and Student. If instances of these classes are related so that students are assigned the ID of one particular classroom, which choice shows the correct associations to define?

1. 

class Classroom < ActiveRecord::Base
  belongs_to :students, class_name: 'Student'
end

class Student < ActiveRecord::Base
  belongs_to :classrooms, class_name: 'Classroom'
end

2. 

class Student < ActiveRecord::Base
  has_many :classrooms, dependent: true
end

class Classroom < ActiveRecord::Base
  has_many :students, dependent: false
end

3. 

class Student < ActiveRecord::Base
  has_many :classrooms
end

class Classroom < ActiveRecord::Base
  belongs_to :student
end

4. 

class Classroom < ActiveRecord::Base
  has_many :students
end

class Student < ActiveRecord::Base
  belongs_to :classroom
end

 

33 / 48

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

34 / 48

What is the correct syntax for inserting a dynamic title tag into the header of your page from within an ERB view template?

1. 

<% render :head do %>
  <title>My page title</title>
<% end %>

2. 

<% content_for :head do %>
  <title>My page title</title>
<% end %>

3. 

<% render "shared/head, locals: {title: "My page title"} %>

4. 

<% tield :head do %>
  <title>My page title</title>
<% end %>

 

35 / 48

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}

 

36 / 48

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

37 / 48

You made a spelling mistake while creating a table for bank accounts. Which code would you expect to see in a migration to fix the error?

1. 

class IAmADummy < ActiveRecord::Migration
  def change
    rename_column :accounts, :account_hodler, :account_holder
  end
end

2. 

class FixSpellling < ActiveRecord::Migration
  def change
    rename :accounts, :account_hodler, :account_holder
  end
end

3. 

class CoffeeNeeded < ActiveRecord::Migration
  def change
    remove_column :accounts, :account_hodler
    add_column :accounts, :account_holder
  end
end

4. 

class OopsIDidItAgain < ActiveRecord::Migration
  def rename
    :accounts, :account_hodler, :account_holder
  end
end

38 / 48

What is before_action (formerly known as before_filter)?

39 / 48

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

40 / 48

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

41 / 48

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

42 / 48

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

43 / 48

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

44 / 48

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

45 / 48

In the model User you have the code shown below. When saving the model and model.is_admin is set to true, which callback will be called?

before_save :encrypt_data, unless: ->(model) { model.is_admin }
after_save :clear_cache, if: ->(model) { model.is_admin }
before_destroy :notify_admin_users, if: ->(model) { model.is_admin }

 

46 / 48

Given this code, which choice would be expected to be a true statement if the user requests the index action?

class DocumentsController < ApplicationController
  before_action :require_login
  def index
    @documents = Document.visible.sorted
  end
end

 

47 / 48

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

48 / 48

If the only route defined is resources :products, what is an example of a URL that could be generated by this link_to method?

link_to('Link', {controller: 'products', action: 'index', page: 3})

1. 

/products?page=3

2. 

/products/index/3

3. 

/products/page/3

4.

/products/index/page/3

Your score is

The average score is 0%

0%

Recommended Articles for you:

Leave a Reply

Your email address will not be published. Required fields are marked *