Menu icon Foundation
Rails: Selective Javascript includes

I've noticed a slight issue using the Foundation gem in Rails, as per the setup instructions: http://foundation.zurb.com/docs/applications.html

All 16 Foundation js files are being rendered in the html. It seems there is no choice to select just the ones you need. Is there an alternative step missing in the setup?

Thanks in advance for replying.

railsjavascript

I've noticed a slight issue using the Foundation gem in Rails, as per the setup instructions: http://foundation.zurb.com/docs/applications.html

All 16 Foundation js files are being rendered in the html. It seems there is no choice to select just the ones you need. Is there an alternative step missing in the setup?

Thanks in advance for replying.

Linhao Zhang over 5 years ago

Also am having trouble with this, I can't seem to be able to do //= require foundation/reveal as this does not work as it did previously.

Scott Greenwald over 5 years ago

Aha! Solved it:

First, delete //= require foundation (which loads everything), and load just the base foundation js:
//= require foundation/foundation

Now, you can load each plugin separately, ex:
//= require foundation/foundation.offcanvas
//= require foundation/foundation.tooltip

Hope this works for you Linhao, and anyone else who stumbles across this post.

Fred Rivett about 4 years ago

Scott, you are a legend! Thanks for this :)

John Chen almost 3 years ago

Just want to amend the answer for foundation-rails gem for Foundation 6. To selectively load Foundation JavaScript libraries, you use, for example, //= require foundation.core

So...

//= require foundation.core

//= require foundation.util.mediaQuery

//= require foundation.util.motion

And so on so forth.

 

The complete list of Foundation JavaScript libraries you can include is here: https://github.com/zurb/foundation-rails/tree/master/vendor/assets/js