Skip to content
Advertisement

Rails gem with javascript dependency

I’m writing a rails gem which requires angular, so I added it to my gem’s dependencies:

s.add_dependency "angularjs-rails", "~> 1.6.2"

Now, how should I include angular ? I tried to add it directly in my gem’s main js script but sprockets fails with this kind of error:

JavaScript

When I try to include angular in an application that uses my gem, before including my gem’s script, the error is quite the same…

So should I just specify that my gem requires angularjs-rails to be added in the app Gemfile, or is there a better way to do this ?

Advertisement

Answer

As Richard Peck proposed, I required angularjs-rails in my gem’s module file, and everything went fine:

JavaScript

And in my gem’s js script:

JavaScript

Thank you 🙂

Advertisement