Skip to content

Commit 3800949

Browse files
committed
Disambiguate language around when code stops re: redirect_to
This paragraph tends to cause confustion with Rails developers who have just learned the correct control flow of `redirect_to` and `render`. A phrase above it in the "Avoiding Double Render Errors" section clears up a common misunderstanding that `render` will stop execution within a controller action. That misunderstanding is further corrected with the following phrase. > But this will _not_ stop the rest of the code in the `show` action from running This section is often enough to get the point across for newer developers who might often be running into double render errors, but soon after the phrase which attempts the same illustration of `redirect_to`'s execution confuses the matter by using the same language as the earlier statement to mean the opposite. > Sometimes inexperienced developers think of `redirect_to` as a sort of `goto` command, moving execution from one place to another in your Rails code. This is _not_ correct. Your code stops running and waits for a new request from the browser. Here "Your code stops running" means that the action will run to completion and not jump to another site in controller code. This often re-confuses the concept they've just learned and undermines their understanding. By being more specific in the second phrase, we can reinforce the concept instead.
1 parent 931c5ef commit 3800949

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

guides/source/layouts_and_rendering.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,14 @@ Just like the `:status` option for `render`, `:status` for `redirect_to` accepts
714714
715715
#### The Difference Between `render` and `redirect_to`
716716
717-
Sometimes inexperienced developers think of `redirect_to` as a sort of `goto` command, moving execution from one place to another in your Rails code. This is _not_ correct. Your code stops running and waits for a new request from the browser. It just happens that you've told the browser what request it should make next, by sending back an HTTP 302 status code.
717+
Sometimes inexperienced developers think of `redirect_to` as a sort of `goto`
718+
command, moving execution from one place to another in your Rails code. This is
719+
_not_ correct.
720+
721+
The current action will complete, returning a response to the browser. After
722+
this your code stops running and waits for a new request, it just happens that
723+
you've told the browser what request it should make next by sending back an
724+
HTTP 302 status code.
718725

719726
Consider these actions to see the difference:
720727

0 commit comments

Comments
 (0)