Question

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

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

<script src='/assets/main.js'></script>

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
0 0
Add a comment Improve this question Transcribed image text
Answer #1

2.old articles controllers will use the old layout

3.apps/view/application

4.True

5.all true

6.stylesheet_link_tag

Add a comment
Know the answer?
Add Answer to:
2.Given the following layout declarations, which of the following is/are true? Select all that applies: application_controller.rb:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design an original, professional web site following the specifications listed below. This web sit...

    Design an original, professional web site following the specifications listed below. This web site will be for a business you plan to set up for yourself or for someone else. The following is a detailed list of the requirements for your web site. READ them carefully. Instructions - Web Site Requirements for the web site: General: You will thoroughly test all your pages in more than one browser. All links MUST work. All graphics must show on the page. All...

  • Don't attempt if you can't attempt fully, i will dislike and negative comments would be given...

    Don't attempt if you can't attempt fully, i will dislike and negative comments would be given Please it's a request. c++ We will read a CSV files of a data dump from the GoodReads 2 web site that contains information about user-rated books (e.g., book titnle, publication year, ISBN number, average reader rating, and cover image URL). The information will be stored and some simple statistics will be calculated. Additionally, for extra credit, the program will create an HTML web...

  • Don't attempt if you can't attempt fully, i will dislike a nd negative comments would be...

    Don't attempt if you can't attempt fully, i will dislike a nd negative comments would be given Please it's a request. c++ We will read a CSV files of a data dump from the GoodReads 2 web site that contains information about user-rated books (e.g., book tit le, publication year, ISBN number, average reader rating, and cover image URL). The information will be stored and some simple statistics will be calculated. Additionally, for extra credit, the program will create an...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT