0

I am implemented Recurly payments into a project, the project is using requirejs and there are requirejs 2 javascript files, 1 named 'front.js.coffee' for customer facing site and the second named 'admin.js.coffee' for the CMS. I have created a global variable as a partial that I render into the website header and then I need the front.js file to pull this value in order to build the Recurly transaction form. I had to do it this way because I need the server to generate a signature so therefore this had to pass through a '*html.erb' file.

So here is the global variable inside a shared view file:

<%= javascript_tag do %>
   signature_value: '<%= j RECURLY_SIGNATURE %>'
<% end %> 

So here is the JS inside the front.js file:

Recurly.config
 subdomain: 'iewebinar'
 currency: 'USD'
 country: 'US'
Recurly.buildTransactionForm
 target: '#recurly-transaction'
 successURL: '/webinars/thank_you.html'
 signature: 'signature_value'

I am new to Ruby on Rails development and I dont entirely understand Requirejs so simple instructions would be great :)

Dan Mitchell
  • 844
  • 2
  • 15
  • 34

1 Answers1

1

before you requiring the js files, you can add

<script>
  window.signature_value = '<%= j RECURLY_SIGNATURE %>'
</script>

then just use window.signature_value in your config.

successURL: '/webinars/thank_you.html'
signature: window.signature_value

one more option is to change the filename to admin.js.coffee.erb. This will give you access to ruby functions so you may have access to the constant (sorry i'm not sure about this).

successURL: '/webinars/thank_you.html'
signature: '<%= RECURLY_SIGNATURE %>'
jvnill
  • 29,479
  • 4
  • 83
  • 86