Reputation: 11774
Caching is the only explanation I can think of for this. I'm using Stripe, and I have the following Javascript to set it up:
$(function() {
console.log("Stripe: ");
console.log($('meta[name="stripe-key"]').attr('content'));
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'));
issueOrder.setupForm();
});
When I directly access the page (i.e., put the exact URL in the address bar) where I make stripe orders, this works great. console.log logs what I'm testing, the stripe token is set up, and the payment goes through without a hitch.
However, when I access the page from a previously accessed page on the site (i.e., clicking a link to the payments page), nothing is logged and the stripe token is not set, leading to a server side error.
It seems like the javascript is being called once, but when a new page is rendered, somehow it recognizes that it has already been called, so it doesn't call the javascript again. Unfortunately, Stripe's publishable key isn't cached, so this leads to a server side error. Am I thinking about this correctly, and if so, how can I get around it?
Upvotes: 0
Views: 46
Reputation: 10673
This is because of Turbolinks - just override the turbolinks for the link that takes you to the page where you are using Stripe.
<a href="url" data-no-turbolink>Link Text</a>
or the Rails way
<%= link_to 'Link Text', url_path, 'data-no-turbolink' => true %>
Upvotes: 1