title: rails 4 controller redirect not loading javascript
body: <p>I am using Rails 4. My <code>root_url</code> is routed to <code>users#new</code>. And I want to redirect to <code>root_url</code> when the user logs out, which is done within the <code>sessions</code> controller. However, after the redirection, the javascript file which contains code in <code>users.js</code> is not loaded. Can anybody explain why this happens? How to resolve it?</p>
  
  <pre><code>class SessionsController &lt; ApplicationController
      ...
      def destroy
          log_out
          redirect_to root_url
      end
  </code></pre>
  
  <p>If this is because <code>users.js</code> is specific to controller <code>users</code>, then what is the best solution for redirection with javascript loaded?</p>
  
  <p>BTW, in my <code>layouts/application.html.erb</code>, I added</p>
  
  <pre><code>&lt;%= debug(params) if Rails.env.development? %&gt;
  </code></pre>
  
  <p>And on the redirected page (which is the root_url), it shows:</p>
  
  <pre><code>--- !ruby/hash:ActionController::Parameters
  controller: users
  action: new
  </code></pre>
  
  <p>I guess this means that now the controller is <code>users</code>. Then why isn't <code>users.js</code> being loaded.</p>
  
  <p>I need a lesson.</p>
  
  <p>---- <code>application.js</code> ----</p>
  
  <pre><code>// This is a manifest file that'll be compiled into application.js, which will include all the files
  // listed below.
  //
  // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
  // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
  //
  // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
  // compiled file.
  //
  // Read Sprockets README (https://github.com/rails/sprockets#sprockets-  directives) for details
  // about supported directives.
  //
  //= require jquery
  //= require jquery_ujs
  //= require turbolinks
  //= require_tree .
  </code></pre>