turbo_form 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa91aad45adf34a36370bd723ccbd9d1034856f813a435225746fdcc233c82da
4
- data.tar.gz: 5be9884b622cd2dad8a37be9794a6c0dcf84b98893f4282fa17bd69d55829014
3
+ metadata.gz: 4cb1af8f341d1112a85f86bc4fe28470e83f867994be6029a32fbd996da03677
4
+ data.tar.gz: 97afa78d913454ea096c0f988ecb85d99f7ebe7027f02f2e19cc40af534b624e
5
5
  SHA512:
6
- metadata.gz: 28cfba558ef2d8151053f282d8a72aa8827857d673f6d23db1917152e7387418a5b22548142d165b01e12cb682634523438a02a1e5c2db4b4d898299b300c7a9
7
- data.tar.gz: 7c8b0e1ab6a8a2fb1470a34084feffb2762ec25294de20aea270749a4b8541b450dc14ecf89889c4ebf86ad1b45b8959c4ae0a72c4afb4f63a987a11fc7e2b50
6
+ metadata.gz: 221fbbcd5e31c6191a208cefb92089f70094ef5709547cdb63984a4bb419342d7109dfe4001135853ee7380537b63d82a8cb2fef64af550d40a1a713dfa93f20
7
+ data.tar.gz: 2e7cd4ecec1194cc7605035e9a51c9dcd1542f3c45410c6497a74221e8ae6a037991650a6d928bdf230097af4cfbc0e7aaf73751326a912f291649b9e22221b4
@@ -26,7 +26,7 @@ class FormRefresh {
26
26
  async start() {
27
27
  this.requestStarted()
28
28
  try {
29
- const response = await Turbo.fetch(this.location, { method: "PATCH", body: new FormData(this.formElement), headers: this.target.headers })
29
+ const response = await Turbo.fetch(this.location, { method: "PATCH", body: new FormData(this.formElement), headers: { ...this.target.headers, "X-CSRF-Token": csrfToken() } })
30
30
 
31
31
  this.target.render(response.status, await response.text())
32
32
  } finally {
@@ -88,6 +88,13 @@ function targetFor(form) {
88
88
  return frame ? new FrameTarget(frame) : new PageTarget()
89
89
  }
90
90
 
91
+ // The form's own authenticity token is scoped to its action and method when
92
+ // per-form tokens are on, as they are by default, so it can't vouch for this
93
+ // PATCH. The page's token can, as it does for Turbo's own submissions.
94
+ function csrfToken() {
95
+ return document.querySelector('meta[name="csrf-token"]')?.content
96
+ }
97
+
91
98
  const triggerSelector = "[data-turbo-form-trigger]"
92
99
 
93
100
  // Shaped like Turbo's observers. One listener per event the page's triggers
@@ -1,3 +1,3 @@
1
1
  module TurboForm
2
- VERSION = '0.7.0'
2
+ VERSION = '0.7.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Cohen