title: Rails update.js.erb not executing javascript
body: <p>I am building a form in rails that will edit an existing question via ajax.</p>
  
  <p>After the form is submitted and the question has been updated, the update method in the controller renders update.js.erb, which will hide the form again.</p>
  
  <p>My problem is that the javascript code in update.js.erb is not executing at all. </p>
  
  <p>I know that the file is rendering because it shows up in the server output, and when I put a</p>
  
  <pre><code>&lt;% raise params %&gt;
  </code></pre>
  
  <p>into it, it works.</p>
  
  <p>However, even the simplest</p>
  
  <pre><code>alert('hello');
  </code></pre>
  
  <p>has no effect in the same file.</p>
  
  <p>I've ruled out javascript and jquery configuration issues because the same code works perfectly in my edit.js.erb file. It's just not working in update.js.erb.</p>
  
  <p>What am I missing?</p>
  
  <p><strong>Edit:</strong> </p>
  
  <p>Firebug shows no errors. Here is the response in firebug's network panel:</p>
  
  <pre><code>alert('hello');
  $('#question_body').replaceWith('&lt;h4&gt;&lt;p&gt;jhsdfjhdsb k jdfs j fjfhds &lt;strong&gt;jfshaflksd;hf sdldfs l fdsalkhdfskhdfs&lt;/strong&gt;;fd lfdksh hfdjaadfhsjladfhsjadfs ;df sjldfsj dfas hafdsj fdas ;ldfas ldfs df dl;hdf fdh ;fdj ;lfads&lt;/p&gt;&lt;/h4&gt;');
  </code></pre>
  
  <p>def update</p>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>This is the controller action:</p>
  
  <pre><code>def update
    respond_to do |format|
      if @question.update_attributes(params[:question])
        format.html { redirect_to @question, :flash =&gt; { :success =&gt; 'Question was successfully updated.' } }
        format.json { head :no_content }
        format.js {}
      else
        format.html { render action: "edit" }
        format.json { render json: @question.errors, status: :unprocessable_entity }
      end
    end
  end
  </code></pre>