0

When I add the JavaScript library to the Rails asset folder and have it configured in my erb file using: <%= javascript_include_tag('scripts.js') %>, the HTML code with the classes associated with the JavaScript file load twice.

I have attached an example here. When I link the JavaScript files to the public folder this issue does not happen, but instead the JavaScript does not show up.

JavaScript

$(function() {
    $("a.page-scroll").bind("click", function(a) {
        var b = $(this);
        $("html, body").stop().animate({
            scrollTop: $(b.attr("href")).offset().top
         }, 1500, "easeInOutExpo"), a.preventDefault()
    })
})

Html.erb

<li>
    <a class="page-scroll" href="#portfolio">Portfolio</a>
</li>
<li>
    <a class="page-scroll" href="#me">About Me</a>
</li>
<li>
    <a class="page-scroll" href="#contact">Contact</a>
</li>

There are no relevant console errors.

Note: This works perfectly fine without Rails.

userlkjsflkdsvm
  • 961
  • 1
  • 21
  • 53
  • It is irrelevant to post a [question twice](http://stackoverflow.com/q/34388869/2945616). – Radix Dec 21 '15 at 06:00
  • as you use `javascript_include_tag(js_file)` and in `application.js` you also use `#// require_tree` as `require_tree .` call only loads the tree for the /app/assets/javascripts/ directory so load it multiple times – Rajarshi Das Dec 21 '15 at 06:37

0 Answers0