2

I am using Stripe to let users subscribe to my Rails 3.2 application. I have a Subscription model, and in the JS asset I call the Stripe object. But I only include the Stripe javascript file in a special layout file for the Subscription process. It's not included in my main Application layout.

So of course I get an error if I don't also include the Stripe JS file on the main Application layout template, because subscription.js.coffee is referencing Stripe.

Is there a way to NOT load the subscription asset except from the special Subscription template I've set up?

RubyRedGrapefruit
  • 12,066
  • 16
  • 92
  • 193

1 Answers1

5

Yes there is, you probably have require_tree in your application.js manifest file.

This means all your coffeescript files including subscriptions.js.coffee are included in your application.js.

Next you probably have a line similar to this one in your layout:

<%= javascript_include_tag 'application' %>

This means that your application manifest file (including the subscription.js.coffee code) is included in your layout.

The solution is to not include this piece of code in your application manifest file.

So in your application.js manifest file instead of of using require_tree, you could do something like this:

//= require jquery
//= require jquery_ujs
//= require posts
//= require comments

And in the manifest file I assume you have for your other layout, you could include subscriptions like this.

//= require_jquery
//= require jquery_ujs
//= require subscriptions

Note that posts and comments are examples.

Arjan
  • 6,264
  • 2
  • 26
  • 42
  • Thanks Arjan. I never thought to have a separate manifest file for the other layout. That was a mental block that you have now removed. – RubyRedGrapefruit Apr 16 '13 at 14:41