title: Javascript only working if placed in view page
body: <p>My rails application uses the Js code only if put within a script tag within the view page, not if it is put into a js file in the asset js folder.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var menu = document.querySelectorAll(".side-menu")[0],
  closedPosition = menu.offsetWidth - 15; //make sure there are 15 pixels showing
  
  Draggable.create(menu, {
    type:"x",
    throwProps:true, //enables the momentum-based flicking (requires ThrowPropsPlugin)
    edgeResistance: 0.9, //you can set this to 1 if you don't want the user to be able to drag past the snap point. This controls how much resistance there is after it hits the max/min.
    maxDuration:0.3, //don't let the animation duration exceed 0.3 second (you can tweak this too of course)
    bounds: {maxX:closedPosition, minX:0}, 
    onClick: function() { //when the user clicks/taps on the menu without dragging, we'll toggle it...
      if (this.target._gsTransform.x === closedPosition) { 
        TweenLite.to(this.target, 0.3, {x:0});
      } else {
        TweenLite.to(this.target, 0.3, {x:closedPosition});
      }
    },
    snap: {
      x: [0, closedPosition]
    }
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>This is the application.html.erb in layouts folder</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;CityScape&lt;/title&gt;
  &lt;link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'&gt;
      &lt;link href='http://fonts.googleapis.com/css?family=Roboto+Slab' rel='stylesheet' type='text/css'&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
  
    &lt;%= javascript_include_tag 'https://cdnjs.cloudflare.com/ajax/libs/gsap/1.17.0/TweenMax.min.js'%&gt;
    &lt;%= javascript_include_tag 'https://cdnjs.cloudflare.com/ajax/libs/gsap/1.17.0/utils/Draggable.min.js'%&gt;
  
  
    &lt;%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' =&gt; true %&gt;
    &lt;%= javascript_include_tag 'application', 'data-turbolinks-track' =&gt; true %&gt;
  
    &lt;%= csrf_meta_tags %&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;%= yield %&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The question is: how to make it works from assets?</p>