title: Return JS in Rails response and have it execute without a .js.erb file
body: <p>I'm currently using this in my controller</p>
  
  <pre><code>respond_to do |format|
    format.html { render :js =&gt; alert('example') }
  end
  </code></pre>
  
  <p>And this in my application.js</p>
  
  <pre><code>$(document).ajaxSuccess( function(event, xhr, settings) {
    if ( settings.url == '/example' ) {
      eval(xhr.responseText)
    } else if ( settings.url.match(/[\/example\/\d]+$/)) {
      eval(xhr.responseText)
      loadComplete()
    } else {
      (etc)
    }
  })
  </code></pre>
  
  <p>To return JS in an ajax response and have the browser execute it. I did this to avoid having to write a new .js.erb file to accommodate each possible response.</p>
  
  <p>Is there a better way of doing this? I thought it would be nice to cut down on the number of files, but having to seperate JS responses using regex on the ajaxSuccess settings.url is pretty gross.</p>