Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2.Given the following layout declarations, which of the following is/are true? Select all that applies: application_controller.rb: class ApplicationController < ActionController::Base layout main end articles_controller.rb: class

2.Given the following layout declarations, which of the following is/are true? Select all that applies:

application_controller.rb: class ApplicationController < ActionController::Base layout "main" end articles_controller.rb: class ArticlesController < ApplicationController end special_articles_controller.rb: class SpecialArticlesController < ArticlesController layout "special" end old_articles_controller.rb: class OldArticlesController < SpecialArticlesController layout false def show @article = Article.find(params[:id]) end def index @old_articles = Article.older render layout: "old" end # ... end
In general, views will be rendered in the main layout
SpecialArticlesController#index will use the special layout
OldArticlesController#show will use no layout at all
OldArticlesController#index will use the old layout
None of the choices.
ArticlesController#index will use the main layout

3.If a template or partial is not found in the conventional path, the controller will look for a template or partial to render in its inheritance chain. Given the following code, what is the lookup order for an admin/products#index action? Enter numeric 1, 2, or 3, where 1 means first and 3 means last.

NOTE: If you aren't sure about this from your reading, you should test this on your computer.

# in app/controllers/application_controller class ApplicationController < ActionController::Base end # in app/controllers/admin_controller class AdminController < ApplicationController end # in app/controllers/admin/products_controller class Admin::ProductsController < AdminController def index end end

app/views/admin/

[ Choose ] 2 1 3

app/views/application

[ Choose ] 2 1 3

app/views/admin/products/

[ Choose ] 2 1 3

4.In Rails, render tells Rails which view (or other asset) to use in constructing a response, whereas the redirect_to method tells the browser to send a new request for a different URL.

True
False

5.Consider the following code showing two different versions of the show method, namely, one with render and the other with redirect_to

def show @book = Book.find_by(id: params[:id]) if @book.nil? render action: "index" end end
def show @book = Book.find_by(id: params[:id]) if @book.nil? redirect_to action: :index end end

Select all that applies. There may be multiple answer(s).

The "redirect_to" command, when executed, stops the code running while it waits for a new request from the browser to arrive as the response to an HTTP 302 status code.
The "render :action" code doesn't run any code in the target action, so nothing will set up the @books variable that the index view will probably require.
The downside to the "redirect_to" code is that it requires a round trip to the browser if controller finds no book in the /books/1 request.
There is no functional difference between both show methods. The results are the same.

6.Rails has several asset tag helpers, which help provide methods for generating HTML that links views to feeds, Javascript, CSS, images, videos, and other assets.

For example, the ojavascript_include_tag translates the following from

<%= javascript_include_tag "main" %>

to

Which of the following is a valid asset tag helper in Rails? Select all that applies. There may be more than one correct answers.

stylesheet_link_tag
image_tag
video_tag
stylesheet_tag
video_tag

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

What is the background of the situation?

Answered: 1 week ago