title: Can I have a JavaScript partial in Ruby on Rails? Partial is trying to render in HTML
body: <p>I have a function that simple selects all of the checkboxes on the current page, creates a form, and submits it automatically.</p>
  <p>Instead of repeating the same exact JavaScript code on every single view, I want to try to just have a shared partial.</p>
  <p>Here's all I have thus far:</p>
  <pre><code>#views/shared/_delete_multiple_items.js.erb
  alert(&quot;&lt;%= random_variable %&gt;&quot;);
  </code></pre>
  <p>.</p>
  <pre><code>#views/users/index.html.erb
  ...
  &lt;script&gt;
    function deleteMulitpleUsers() {
      &lt;%= render 'shared/delete_multiple_items', :locals =&gt; {:random_variable =&gt; &quot;Hello World&quot; %&gt;
    }
  &lt;/script&gt;
  </code></pre>
  <p>It looks like Rails is trying to render the partial in HTML though, if I understand this error correctly:</p>
  <blockquote>
  <p>Missing partial shared/_delete_multiple_items with {:locale=&gt;[:en],
  :formats=&gt;[:html], :variants=&gt;[], :handlers=&gt;[:raw, :erb, :html,
  :builder, :ruby, :coffee, :jbuilder]}. Searched in:</p>
  </blockquote>
  <p>I've tried to include <code>:formats =&gt; :js</code> with render, like this:</p>
  <pre><code>&lt;%= render 'shared/delete_multiple_items', :locals =&gt; {:random_variable =&gt; &quot;Hello World&quot;, :formats =&gt; :js %&gt;
  </code></pre>
  <p>but I still get the same exact error.</p>