title: How to load a custom js file with a controller?
body: <p>If I follow <code>user_create_path</code>, the file "views/users/create.js.erb" will be run, if I'm using this code:</p>
  
  <p><strong>users_controller.br</strong></p>
  
  <pre><code>def create
    #...
    respond_to do |format|
      format.html { redirect_to root_path }
      format.js
    end
  end
  </code></pre>
  
  <p>How can I conditionally load different js files?</p>
  
  <p>I'm thinking of something along these lines:</p>
  
  <pre><code>def create
    #...
    if User.all.count &lt; 50
      respond_to do |format|
        format.html { redirect_to root_path }
        format.js { create_a.js.erb }
      end
    else
      respond_to do |format|
        format.html { redirect_to root_path }
        format.js { create_b.js.erb }
      end
    end
  end
  </code></pre>