Reputation: 139
I am trying to use a plugin called Shuffletext to give my text a shuffling effect that iterates through different strings. this is the code for it (just have it in the .erb file while trying to get it how to work cause its easier)
<div id="wrapper"></div>
<script type="text/javascript">
$('#wrapper').ShuffleText([
'Hello world !',
"I'm a jquery plugin",
"I like to <strong>shuffle text</strong> !"
],{loop: true, delay: 5000, shuffleSpeed: 50});
</script>
In a simple folder that just has a .html file and the plugin file it works fine, but when I put it into ruby it throws me this error
home:24 Uncaught TypeError: $(...).ShuffleText is not a function
at home:24
I've been trying for a few hours to try and fix this and I am stumped, any help is really appreciated, here is a link to the plugin if it helps
https://github.com/Nyl000/ShuffleText
Upvotes: 1
Views: 37
Reputation: 1317
I suppose, you didn't plug in this library correctly. I didn't find a gem that integrates this plugin into Rails asset pipeline, so you should put plugin file into vendor/assets/javascripts
directory. Just copy shuffletext.jquery.js
to this folder.
Then you can either add //= require shuffletext.jquery.js
to manifest file (usually it's app/assets/javascripts/application.js
) after jQuery, or manually add javascript_include_tag 'shuffletext.jquery'
to required pages.
If you decided to require plugin in manifest, you can use it on every page where the manifest is plugged. Usually it is plugged in layout, so all pages that use this layout will have it.
If you decided to use javascript_include_tag
, you also should add Rails.application.config.assets.precompile += %w( shuffletext.jquery.js )
to your config/initializers/assets.rb
file. In this case you will get your plugin only on those pages where you have specified javascript_include_tag
.
Upvotes: 1