Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disambiguate language around when controller code stops re: redirect_to [ci skip] #51032

Conversation

DoodlingDev
Copy link
Contributor

Motivation / Background / Description

Changes to: Layouts and Rendering: 2.3.2 The Difference Between render and redirect_to

The changed 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 clarified with a 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, where the other phrase "stop the rest of the code ... from running" is used to illustrate the misunderstanding and means the action will not run to completion. 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.

The change

Open to feedback around the particular phrasing or formatting, the important part is changing the re-use of the "stops ... running" terminology.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

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.
@rails-bot rails-bot bot added the docs label Feb 9, 2024
@seanpdoyle
Copy link
Contributor

cc: @p8 or @zzak are either of you able to review these changes?

Copy link
Member

@skipkayhil skipkayhil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

@skipkayhil skipkayhil merged commit a7c68d4 into rails:main Feb 9, 2024
3 checks passed
@skipkayhil
Copy link
Member

Thanks for the PR 🎉

skipkayhil added a commit that referenced this pull request Feb 9, 2024
…ils--redirect-to-disambiguation

Disambiguate language around when controller code stops re: `redirect_to` [ci skip]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants