Skip to content

Commit

Permalink
Merge pull request #43855 from nvasilevski/button-to-changes-to-relea…
Browse files Browse the repository at this point in the history
…se-notes

Clarify `button_to` helper changes in Rails 7.0
  • Loading branch information
rafaelfranca committed Dec 15, 2021
2 parents 52c0711 + f52a6f4 commit 9f4ca18
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions guides/source/7_0_release_notes.md
Expand Up @@ -88,6 +88,15 @@ Please refer to the [Changelog][action-view] for detailed changes.

### Notable changes

* `button_to` infers HTTP verb [method] from an Active Record object if object is used to build URL

```ruby
button_to("Do a POST", [:do_post_action, Workshop.find(1)])
# Before
#=> <input type="hidden" name="_method" value="post" autocomplete="off" />
# After
#=> <input type="hidden" name="_method" value="patch" autocomplete="off" />

Action Mailer
-------------

Expand Down
17 changes: 17 additions & 0 deletions guides/source/upgrading_ruby_on_rails.md
Expand Up @@ -81,6 +81,23 @@ Upgrading from Rails 7.0 to Rails 7.1
Upgrading from Rails 6.1 to Rails 7.0
-------------------------------------

### `ActionView::Helpers::UrlHelper#button_to` changed behavior

Starting from Rails 7.0 `button_to` renders a `form` tag with `patch` HTTP verb if a persisted Active Record object is used to build button URL.
To keep current behavior consider explicitly passing `method:` option:

```diff
-button_to("Do a POST", [:my_custom_post_action_on_workshop, Workshop.find(1)])
+button_to("Do a POST", [:my_custom_post_action_on_workshop, Workshop.find(1)], method: :post)
```

or using helper to build the URL:

```diff
-button_to("Do a POST", [:my_custom_post_action_on_workshop, Workshop.find(1)])
+button_to("Do a POST", my_custom_post_action_on_workshop_workshop_path(Workshop.find(1)))
```

### Spring

If your application uses Spring, it needs to be upgraded to at least version 3.0.0. Otherwise you'll get
Expand Down

0 comments on commit 9f4ca18

Please sign in to comment.