Stripe token not getting attached to request body for Rails App

后端 未结 1 568
别那么骄傲
别那么骄傲 2020-12-11 11:30

I am making a Rails App that allows users to become subscribing users for $X/yr and I am stuck on the subscriptions page where whatever I do the stripeToken doesn\'t get att

相关标签:
1条回答
  • 2020-12-11 12:19

    After running this code locally I saw a couple of things:

    I noticed that subscriptions.js isn't being included using the rails helper method javascript_include_tag. Unless you've placed your script in your app's public/js folder than your script probably isn't on the page.

    Assuming that you do have it in public/js and it is on the page, I noticed this error when submitting the form:

    Uncaught TypeError: $form.find(...).prop is not a function
    

    Because of this error, your submit handler never reaches the return false to prevent the form from submitting thus it submits without the stripe token.

    The version of jquery that's on the page is 1.3.2 which .prop isn't available for which is the reason for this error.

    If you don't want to upgrade your version of jquery you can replace .prop with .attr:

    $form.find('button').prop('disabled', true);
    

    becomes:

    $form.find('button').attr('disabled', true);
    

    Also, if you want to ensure that the form doesn't submit (assuming javascript is enabled) I typically add this line at the very beginning of my submit handler:

    event.preventDefault();
    

    This should ensure that your form doesn't submit. You can also remove the return false at the end of your handler as that would no longer be required.

    0 讨论(0)
提交回复
热议问题