1

I have a CoffeeScript file called subscribers.coffee.erb

$(document).ready -> 
  stripe = require('stripe')('<%= Rails.configuration.stripe[:publishable_key]%>')

  $('.pricing-get-started').prop("disabled", true)
  $('.verify-coupon').click ->
    # use stripe api to verify that the coupon is valid

  return
return

The second line does not seem to be working. I have even tried to copy and past my publishable key but that doesn't work either. I think the following problems are:

  1. require('stripe') isn't found
  2. Rails cannot locate the publishable key from the coffeescript file

Note:

I have a working key. I can sign up for subscriptions and everything from my subscribers/new.html.haml.

I am using gem 'stripe'

Any advice would be greatly appreciated!

4
  • @muistooshort I edited that issue and fixed it. That wasn't in my actual code (must of gotten deleted when I was moving some stuff around in the editor on here). Anyways, do you have any other suggestions as to why this is not working? Is there another way I can access the publishable key or stripe.js? Commented May 7, 2016 at 16:15
  • Is it that require isn't working or that require can't find Stripe? Commented May 7, 2016 at 18:23
  • @muistooshort I am not sure. I am using gem stripe and from the looks of it, it seems that the stripe.js file should be available in the asset pipeline. That is why I thought require might be working and there was an issue with rails finding the publishable_key Commented May 7, 2016 at 18:25
  • Any errors anywhere? Are you sure Rails.configuration.stripe[:publishable_key] is right when you're compiling assets? Commented May 7, 2016 at 18:44

1 Answer 1

1

You're calling stripe = require('stripe'), but require isn't defined by default in javascript. As long as you have stripe.js included in your application before this script is called the require('stripe') line should be unnecessary.

Once Stripe.js is loaded you can set your publishable key via Stripe.setPublishableKey('pk_test_key_here');. If you're using an environment variable, be sure that Rails.configuration.stripe[:publishable_key] is defined in your environment.

Finally, you should be aware that any embedded ruby in an asset file included in your asset manifest (application.js or application.css) will not be called on each request, but will only be called when you run rake assets:precompile. Thus Rails.configuration.stripe[:publishable_key] may not always evaluate to a value you expect.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.