title: Rails 3.1: The new way to use 'respond_to ... format.js'  without the 'page' variable
body: <p>I am trying to update Ruby on Rails to the version <strong><em>3.1</em></strong>. I followed the <a href="http://railscasts.com/episodes/282-upgrading-to-rails-3-1" rel="nofollow">Upgrading to Rails 3.1</a> screencast and all seems to work except for statements as</p>
  
  <pre><code>format.js { render(:update) { |page| page.redirect_to @article } }
  </code></pre>
  
  <p>In many controllers I have code like the following:</p>
  
  <pre><code>def create
    ...
  
    respond_to do |format|
      format.js { render(:update) { |page| page.redirect_to @article } }
    end
  end
  </code></pre>
  
  <p>In all above cases, when I try to submit related forms performing JS requests, I get the following error:</p>
  
  <pre><code>ActionView::MissingTemplate (Missing template articles/update, application/update with {:handlers=&gt;[:erb, :builder, :coffee], :formats=&gt;[:js, :html], :locale=&gt;[:en, :en]}. Searched in:
    * "/&lt;MY_PROJECT_PATH&gt;/app/views"
  ):
  
  app/controllers/articles_controller.rb:114:in `create'
  
  Rendered /&lt;...&gt;/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/missing_template.erb within rescues/layout (0.3ms)
  </code></pre>
  
  <p>I know that the problem was related to RJS templates because them are not more available in the 3.1 release. So, in order to run some JavaScript code, in my controller files I may\should\can insert some JavaScript code as made in the following example:</p>
  
  <pre><code>format.js { render :js =&gt; "alert('Hello Rails');" }
  </code></pre>
  
  <p><em>BTW</em> : ...<em>but</em>, <strong>is it recommended to use JavaScript code directly in a controller file?</strong></p>
  
  <p>Considering the above code in the <code>create</code> controller action, I would like to redirect user to the <code>@article</code> path after a successful submission. I can do:</p>
  
  <pre><code>format.js { render :js =&gt; "window.location.replace('#{article_url(@article)}');" }
  </code></pre>
  
  <p>..but, <strong>how can I do the same thing <em>by following</em> the "Ruby on Rails Way to do things"? How RoR 3.1 would handle these cases?</strong></p>