mattman88
mattman88

Reputation: 495

Cannot Import Javascript File To html.erb file

I am trying to import a file called ng-infinite-scroll.min.js in a html.erb file (titled application.html.erb). I know .erb stands for embedded ruby.

Giving the absolute path to the file like so causes an error:

<script src="/Users/username/Nasiki/app/assets/javascripts/ng-infinite-scroll.min.js"></script>

The error reads out in the console:

"GET http://localhost:3000/Users/username/Nasiki/app/assets/javascripts//ng-infinite-scroll.min.js"

Note that I am running this server locally and so the home for my website is:

http://loclhost:3000

Why can't it find this file given the absolute path. I've tried a lot of different paths, it may have to do with how .erb files accept paths. Does anybody know? Thanks

Upvotes: 0

Views: 1380

Answers (1)

emaxi
emaxi

Reputation: 1809

Use this:

<% javascript_include_tag 'ng-infinite-scroll.min' %>

Below is the documentation:

http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-javascript_include_tag

Upvotes: 2

Related Questions