Commit Graph

143 Commits

Author SHA1 Message Date
Sean Doyle
32faee0e52 Action View: docs use application/ instead of shared/
Change mentions of `app/views/shared` in the guides to be
`app/views/application` instead. View partials rely on the same
[Template Inheritance][] as their template counterparts, so the guides
should encourage end-users to benefit from that inheritance.

> This makes `app/views/application/` a great place for your shared
> partials, which can then be rendered in your ERB as such:
>

```html+erb
<%# app/views/admin/products/index.html.erb %>
<%= render @products || "empty_list" %>

<%# app/views/application/_empty_list.html.erb %>
There are no items in this list <em>yet</em>.
```

To enforce that template resolution, this commit also replaces
references to `shared/` with `application/` in the Rails test suite.

[Template Inheritance]: https://guides.rubyonrails.org/layouts_and_rendering.html#template-inheritance
2023-09-15 12:06:22 -04:00
matt swanson
a9f1558be5
Typo 2023-06-14 00:05:36 -04:00
matt swanson
bcd5dd6c8d
Add notes about renderable option to guide 2023-06-13 23:53:42 -04:00
zzak
dadf46de36
Add rubocop-md for linting guides snippets 2023-03-15 10:48:19 +09:00
Jonathan Hefner
aaf7bed003 Document ActionController::Rendering#render [ci-skip]
In #33418, documentation from `ActionView::Helpers::RenderingHelper#render`
was copied to `ActionController::Renderer#render` with the intention of
documenting `ActionController::Rendering#render`.  Since then, further
documentation has been added to `ActionController::Renderer#render`, and
`ActionController::Renderer#render` has been mistaken for
`ActionController::Rendering#render` (for example, in #46045).

This commit adds documentation to `ActionController::Rendering#render`
(which was previously `:nodoc:` because it is a simple override of
`AbstractController::Rendering#render`), and updates related
documentation to point to `ActionController::Rendering#render`.
2023-01-08 15:47:31 -06:00
Missy Davies
d49a3abc01 Capitalize headings to match style guidelines
Fix all headings to follow Rails Guides Guidelines
2022-10-17 17:01:28 -10:00
Sreeram Venkitesh
66b583f414 Fix link for ActionController in Layouts and Rendering docs 2022-09-15 22:30:42 +05:30
Sreeram Venkitesh
dd6d6229aa Changed ActionController to AbstractController 2022-09-14 01:10:28 +05:30
Ryo Nakamura
a5065d4abc Avoid using render(...) and return in example code 2022-09-02 06:33:43 +09:00
Alex Ghiculescu
5a069ae262 Docs: clarify where counter variables start
The way the guide is written now, it's not clear if the first counter value will be `0` or `1`, so I made it explicit that it's `0`.

Co-authored-by: Petrik de Heus <petrik@deheus.net>
2022-06-06 11:37:32 -05:00
Ghouse Mohamed
a12305a2e8 Fixes controller name highlight in guide 2022-02-23 04:16:04 +05:30
Ghouse Mohamed
ea0685fee9 Fixed typo: HTML 5 -> HTML5 2022-02-21 02:34:46 +05:30
Jonathan Hefner
c01b48e5fa Add Oxford commas [ci-skip] 2022-02-13 13:07:51 -06:00
Ryuta Kamizono
296ef7a172 Update layouts_and_rendering.md using turbo [ci-skip] 2021-12-27 18:47:44 +09:00
akhilgkrishnan
d5962ff062 Fix punctuation of layout and rendering doc 2021-06-27 20:40:21 +05:30
John Bampton
eef63e05fb chore: fix case of CSS and JavaScript 2021-04-15 21:52:58 +10:00
André Luis Leal Cardoso Junior
1280620767 Remove legacy media=screen default from stylesheet_link_tag.
If the media attribute is omitted, the default for web browsers is "all", meaning that by default links apply to all media.

Before:

```ruby
> stylesheet_link_tag "style"
=> <link href="/assets/style.css" media="screen" rel="stylesheet" />
```

After:

```ruby
> stylesheet_link_tag "style"
=> <link href="/assets/style.css" rel="stylesheet" />

```

The current behavior is not going to change for existing applications.

For newly built applications, the media attribute is not going to be added by default. Which can be configured using the following:

```
Rails.application.config.action_view.stylesheet_media_default = false
```
2021-01-22 20:42:22 -03:00
Santiago Bartesaghi
e83d7dcb2f Use 4XX instead of 2XX for validation errors responses 2021-01-06 00:10:26 -03:00
Jonathan Hefner
cb0da4f817 Fix typos, grammar, and formatting [ci-skip]
This is a collection of minor superficial improvements.  It does not
include any significant content changes.
2020-12-28 12:05:53 -06:00
Jonathan Hefner
f3f36e7ef7 Fix syntax highlighting [ci-skip]
This fixes the syntax highlighting of several code snippets by changing
the code fences to the correct language.
2020-12-25 21:03:11 -06:00
Jonathan Hefner
384c0d4b2f Fix list item indentation [ci-skip]
This fixes the formatting of list items that include code snippets and
multiple paragraphs.
2020-12-25 13:29:13 -06:00
Jonathan Hefner
cb563a27de Split code snippets by context [ci-skip]
This provides a stronger visual cue that the code in these snippets
belongs in different contexts (e.g. separate files).
2020-12-25 10:53:12 -06:00
Jonathan Hefner
83cfcda3ad Link to API docs in Layouts and Rendering guide [ci-skip]
This links the first mention of each method to its API documentation,
similar to a Wikipedia article.  Some subsequent mentions are also
linked, when it suits the surrounding text.
2020-11-08 21:07:19 -06:00
Joel Hawksley
136b814144 Include layout when rendering objects from controllers
In https://github.com/rails/rails/pull/37919, support
for rendering objects that respond_to render_in in
controllers was added. However, the implementation
did not support layouts.

This change updates the implementation from #37919
to more closely match the rest of the
ActionView::Template classes, enabling the use of layouts.

Co-authored-by: Felipe Sateler <fsateler@gmail.com>
2020-10-14 11:49:45 -06:00
Chirag
84d6a0e568 Formats code blocks for better syntax highlighting 2020-08-21 15:47:32 +05:30
Michael Hagar
b9c05c0fe1 Remove reference to rendering absolute files
Update guides/source/layouts_and_rendering.md

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2020-06-20 10:36:44 -05:00
Michael Hagar
19c6855075
Add comma after however
Not having the comma changes the meaning of the word - from "any way" with no comma, to "but actually" with a comma. It is the latter meaning the guides are intending.
2020-06-18 21:17:52 -05:00
Joel Hawksley
c82a9193df
Document view components support (#38656) 2020-03-13 23:52:49 +01:00
Thais Kusuki
4069282d74 Fix typo in Options for render [ci skip] 2019-11-30 11:34:08 -03:00
Jonathan Hefner
f2cedf9151 Update form examples [ci skip]
Convert examples to use `form_with` instead of `form_for` or `form_tag`,
which have been soft-deprecated.  Also rename form variable in examples
from `f` to `form`, as exemplified by 8ff7ca5d11.
2019-11-01 18:10:36 -05:00
John Hawthorn
9fe5aa32a7 Update guide for render file:
Most of this section was written from the time that render file: was the
default, before CVE-2016-0752.

This updates the guide to the Rails 6 `render file:` behaviour, moves it
to a more appropriate part of the file.

[ci skip]
2019-07-13 21:32:13 -07:00
John Hawthorn
85fa9b6549 Remove obsolete or discouraged render examples
Most of these examples no longer work. The ability to render an absolute
path was removed as part of CVE-2016-0752. In Rails 6 we changed `render
file:` to only take exact paths and always to render them as raw files.
Rendering a template with its extensions _is_ supported, but I don't
think should be recommended.

This also removes `render file:` from an example where it isn't
relevant.

[ci skip]
2019-07-13 21:32:11 -07:00
Saheed Oladele
c8bc3c2943
Fix typo by changing 'for' to 'from' 2019-04-21 08:07:42 +01:00
Edward Rudd
1b645333bc fix typo in the guides (use Rails instead of rails) 2019-04-04 17:58:37 -04:00
Edward Rudd
90a8ce6450 add documentation about variants 2019-04-03 18:10:09 -04:00
Nathaniel Suchy
d9f1cc05b5 Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
Lucas Oliveira
8d5a2c4da1 Update guide for the counter variable when rendering with the as: option
[ci skip]
2018-10-16 20:52:34 -04:00
Paul McMahon
7b9c19d94b Rails guides are now served over https
http links will be redirected to the https version, but still better to
just directly link to the https version.
2018-07-24 11:29:31 +09:00
Yong Bakos
1de3c0dd1b Capitalize class name 'Product'.
In this context, the phrase 'product instance' refers to the Product class,
so capitalize it.
2018-06-01 02:41:25 -04:00
Anthony Crumley
258670244d Added a lot of Oxford commas
[ci skip] A regular expression was used to find a lot of missing Oxford
commas and add them.  The regular expression was as follows.

", ([a-zA-Z0-9.\`:'\"]+ ){1,6}(or|and) "
2018-05-10 12:46:06 -05:00
bogdanvlviv
264f4a6b14
Update "Layouts and Rendering in Rails" guide [ci skip]
- Remove mention about `ActionView::TemplateHandlers` since this
    module was removed by c1304098cca8a9247a9ad1461a1a343354650843.
    Change word `subclasses` to `nested classes`.
    See c7408a0e40545558872efb4129fe4bf097c9ce2f
  - Remove useless sentence "Beginning with Rails 2, the standard extensions
    are `.erb` for ERB (HTML with embedded Ruby), and `.builder` for Builder (XML generator)."
2018-01-17 16:31:08 +02:00
Avneet Singh Malhotra
b01cc6663f Correct render method's response header's content type for option(:body) from text/html to text/plain. (#31212) 2017-11-24 13:38:21 +05:30
Rob
0bcfa999b8 Update layouts_and_rendering.md [ci skip] 2017-11-14 13:26:01 +00:00
Neil Matatall
521266f913 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.
2017-09-27 07:14:37 -10:00
Yoshiyuki Hirano
a52e2bed86 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.
2017-09-17 07:40:58 +09:00
yuuji.yaginuma
b692955214 Add missing http status codes [ci skip]
Ref: 5401f776f6,
73e08279d4
2017-07-04 12:59:05 +09:00
Jorge Dias
1f48de101b Specify correct extension for text layouts
When using render plain the extension for the layout needs to be .text.erb instead of .txt.erb
2017-06-29 00:16:41 +02:00
Yong Bakos
4d433f8d21 Guides: Clarify partial local variable naming.
Clarify the partial local variable name as being the same as the name
of the partial, minus the _leading_ underscore.
2017-06-23 22:44:55 -07:00
Mike Gunderloy
062e5f2b06
Add :json type to auto_discovery_link_tag
This allows auto_discovery_link_tag to support the JSON Feed standard.
See https://jsonfeed.org/version/1 for more information.
2017-05-20 04:00:13 -05:00
Kasper Timm Hansen
eb4aba0052 [ci skip] Fully qualify missing template error.
Switch extension 👉 format as it's more apt here.
2017-02-11 21:58:36 +01:00