So I am trying to get my code to match Stripe's js example:
var stripe = Stripe('pk_test_REST_OF_MY_KEY');
Here are the lines from my .js.erb file that call the right key from my secrets.yml file. When this renders I get the following error in the browser console Uncaught ReferenceError: pk_test_REST_OF_MY_KEY is not defined
var stripe = Stripe(
<% if Rails.env == 'production' %>
<%= Rails.application.secrets.stripe(['publishable_key']).second[1].to_s %>
<% else %>
<%= Rails.application.secrets.stripe(['publishable_key']).first[1].to_s %>
<% end %>
);
I've tried
... Stripe(`
RUBY LINES BETWEEN BACKTICKS
`);
... Stripe(' +
RUBY LINES BETWEEN PLUSES
+ ');
So it has to be some finicky js syntax with the (' '); not accepting the ruby value as a string, right? We know the ruby is running because the console error is printing the right value.
Also, the ruby is correct because it produces Rails.application.secrets.stripe(['publishable_key']).first[1].to_s
=> "pk_test_REST_OF_MY_KEY" in the console