From a52e2bed8634531272018a4ae7ba389e1feebdf5 Mon Sep 17 00:00:00 2001 From: Yoshiyuki Hirano Date: Sat, 16 Sep 2017 08:33:57 +0900 Subject: Update Layouts and Rendering in Rails [ci skip] * The example code on this page are similar to ones generated by scaffold generator, but some points are different. * Of course, it is no reason to be as same as scaffolding codes. But this is the guide for beginners, I thought it's better to be almost same as scaffolding codes. --- guides/source/layouts_and_rendering.md | 36 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'guides/source/layouts_and_rendering.md') diff --git a/guides/source/layouts_and_rendering.md b/guides/source/layouts_and_rendering.md index 76b325d0bf..fe2477f2ae 100644 --- a/guides/source/layouts_and_rendering.md +++ b/guides/source/layouts_and_rendering.md @@ -71,23 +71,25 @@ If we want to display the properties of all the books in our view, we can do so

Listing Books

- - - - - - - - -<% @books.each do |book| %> - - - - - - - -<% end %> + + + + + + + + + + <% @books.each do |book| %> + + + + + + + + <% end %> +
TitleSummary
<%= book.title %><%= book.content %><%= link_to "Show", book %><%= link_to "Edit", edit_book_path(book) %><%= link_to "Remove", book, method: :delete, data: { confirm: "Are you sure?" } %>
TitleContent
<%= book.title %><%= book.content %><%= link_to "Show", book %><%= link_to "Edit", edit_book_path(book) %><%= link_to "Destroy", book, method: :delete, data: { confirm: "Are you sure?" } %>

-- cgit v1.2.3 From 521266f913083c3029567ffe647e08e39af7f18a Mon Sep 17 00:00:00 2001 From: Neil Matatall Date: Wed, 27 Sep 2017 07:14:37 -1000 Subject: Encourage html-safe API in layouts/rendering guide While the code example was not unsafe, it encourages the use of confusingly unsafe APIs (specifically `html_safe`). We have a safe alternative and we should encourage people to use it under all circumstances. --- guides/source/layouts_and_rendering.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source/layouts_and_rendering.md') diff --git a/guides/source/layouts_and_rendering.md b/guides/source/layouts_and_rendering.md index fe2477f2ae..b9b327252f 100644 --- a/guides/source/layouts_and_rendering.md +++ b/guides/source/layouts_and_rendering.md @@ -232,14 +232,14 @@ You can send an HTML string back to the browser by using the `:html` option to `render`: ```ruby -render html: "Not Found".html_safe +render html: helpers.tag.strong('Not Found') ``` TIP: This is useful when you're rendering a small snippet of HTML code. However, you might want to consider moving it to a template file if the markup is complex. -NOTE: When using `html:` option, HTML entities will be escaped if the string is not marked as HTML safe by using `html_safe` method. +NOTE: When using `html:` option, HTML entities will be escaped if the string is not composed with `html_safe`-aware APIs. #### Rendering JSON -- cgit v1.2.3 From 0bcfa999b8deb7ea5d15dab9597bc637d226b565 Mon Sep 17 00:00:00 2001 From: Rob Date: Tue, 14 Nov 2017 13:26:01 +0000 Subject: Update layouts_and_rendering.md [ci skip] --- guides/source/layouts_and_rendering.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source/layouts_and_rendering.md') diff --git a/guides/source/layouts_and_rendering.md b/guides/source/layouts_and_rendering.md index b9b327252f..f4597b0e60 100644 --- a/guides/source/layouts_and_rendering.md +++ b/guides/source/layouts_and_rendering.md @@ -1266,7 +1266,7 @@ You can also pass in arbitrary local variables to any partial you are rendering In this case, the partial will have access to a local variable `title` with the value "Products Page". -TIP: Rails also makes a counter variable available within a partial called by the collection, named after the member of the collection followed by `_counter`. For example, if you're rendering `@products`, within the partial you can refer to `product_counter` to tell you how many times the partial has been rendered. This does not work in conjunction with the `as: :value` option. +TIP: Rails also makes a counter variable available within a partial called by the collection, named after the title of the partial followed by `_counter`. For example, when rendering a collection `@products` the partial `_product.html.erb` can access the variable `product_counter` which indexes the number of times it has been rendered within the enclosing view. You can also specify a second partial to be rendered between instances of the main partial by using the `:spacer_template` option: -- cgit v1.2.3 From b01cc6663f91e825ffdf862a761e7bfc3d2ffd85 Mon Sep 17 00:00:00 2001 From: Avneet Singh Malhotra Date: Fri, 24 Nov 2017 13:38:21 +0530 Subject: Correct render method's response header's content type for option(:body) from text/html to text/plain. (#31212) --- guides/source/layouts_and_rendering.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source/layouts_and_rendering.md') diff --git a/guides/source/layouts_and_rendering.md b/guides/source/layouts_and_rendering.md index f4597b0e60..4d79b2db89 100644 --- a/guides/source/layouts_and_rendering.md +++ b/guides/source/layouts_and_rendering.md @@ -285,7 +285,7 @@ the response. Using `:plain` or `:html` might be more appropriate most of the time. NOTE: Unless overridden, your response returned from this render option will be -`text/html`, as that is the default content type of Action Dispatch response. +`text/plain`, as that is the default content type of Action Dispatch response. #### Options for `render` -- cgit v1.2.3