I was having a hell of a time getting Stripe Elements to work with Turbolinks 5, specifically the Turbolinks iOS wrapper. Hopefully others who see the same issues can benefit from what I learned.
The symptoms were:
- Stripe Elements worked in the desktop browser, in mobile safari, but not in the Turbolinks-enabled iOS app
What I learned:
- For Turbolinks-enabled iOS apps, all forms must be sent via AJAX w/
remote: true(or the absence of
local: truedepending on your version of Rails)
- When using
rails-ujs, you must intercept the
ajax:beforeevent and call
event.preventDefaultuntil the Stripe JS library has had a chance to retrieve the token
- Once the token has been retrieved and added to the form, you must call
- In your interception of
ajax:beforethis time, you must not call
event.preventDefault()since you now have the token
At least I learned a lot about how rails-ujs, turbolinks, and Stripe Elements work under the hood!