Fix a button_to documentation example#37190
Merged
gmcgibbon merged 1 commit intorails:masterfrom Sep 13, 2019
glacials:fix_a_button_to_example
Merged
Fix a button_to documentation example#37190gmcgibbon merged 1 commit intorails:masterfrom glacials:fix_a_button_to_example
gmcgibbon merged 1 commit intorails:masterfrom
glacials:fix_a_button_to_example
Conversation
Fixes an example in `button_to`'s documentation; the description states
`button_to` only takes a symbol for the `method` argument, but an
example just below uses a string.
Passing an all-lowercase string incidentally works, so the example is
technically functional despite being undefined behavior. But passing an
all-uppercase string fails, and this is a pretty common practice when
specifying HTTP methods (e.g. `DELETE`), so I think it's best this
example is put in line with the documentation and converted to use
symbols.
I fell for it myself and tried to pass an all-uppercase string after
seeing the example without reading the options descriptions.
Reproduction steps:
```sh
rails new buttonto
cd buttonto
rails c
> def protect_against_forgery?
> false
> end
=> :protect_against_forgery?
> button_to('Destroy', 'http://www.example.com', method: "delete", remote: true, data: { confirm: 'Are you sure?', disable_with: 'loading...' })
=> "<form class=\"button_to\" method=\"post\" action=\"http://www.example.com\" data-remote=\"true\"><input type=\"hidden\" name=\"_method\" value=\"delete\" /><input data-confirm=\"Are you sure?\" data-disable-with=\"loading...\" type=\"submit\" value=\"Destroy\" /></form>"
> button_to('Destroy', 'http://www.example.com', method: "DELETE", remote: true, data: { confirm: 'Are you sure?', disable_with: 'loading...' })
=> "<form class=\"button_to\" method=\"post\" action=\"http://www.example.com\" data-remote=\"true\"><input data-confirm=\"Are you sure?\" data-disable-with=\"loading...\" type=\"submit\" value=\"Destroy\" /></form>"
```
gmcgibbon
approved these changes
Sep 13, 2019
Member
gmcgibbon
left a comment
There was a problem hiding this comment.
Thanks! For next time, please use [ci skip] for doc only changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an example in
button_to's documentation; the description statesbutton_toonly takes a symbol for themethodargument:but an example just below uses a string:
Passing an all-lowercase string incidentally works, so the example is technically functional despite being undefined behavior. But passing an all-uppercase string fails, and this is a pretty common practice when specifying HTTP methods (e.g.
DELETE), so I think it's best this example is put in line with the documentation and converted to use a symbol.Reproduction steps:
Other Information
I fell for this example myself and tried to pass an all-uppercase string after seeing the example without reading the options descriptions.