title: Simple UJS with jQuery not working in Rails 3
body: <p>I'm creating a basic message board app with Rails 3. I want posts to be created with UJS/jQuery (submit the post with AJAX and clear the form). I thought this would be simple but I'm getting this error:</p>
  
  <pre><code>Rendered posts/create.js.erb (64.5ms)
  Completed   in 1771ms
  
  ActionView::Template::Error (undefined local variable or method `posts' for #&lt;#&lt;Class:0x1d681d0&gt;:0x1d66f10&gt;):
      1: $("#posts").html("&lt;%= escape_javascript(render(:partial =&gt; posts)) %&gt;");
      2: $("#form").html("&lt;%= escape_javascript(render 'form') %&gt;");
    app/views/posts/create.js.erb:1:in `_app_views_posts_create_js_erb__431255654_15413772__591965598'
    app/controllers/posts_controller.rb:41:in `create'
  
  Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (10.5ms)
  Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (53.8ms)
  Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (95.0ms)
  </code></pre>
  
  <p>layouts/application.html.erb:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;&lt;%= @title || controller.action_name %&gt;&lt;/title&gt;
      &lt;%= stylesheet_link_tag 'style' %&gt;
      &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;
      &lt;%= javascript_include_tag 'jquery.timeago','jquery.watermark', 'rails' %&gt;
      &lt;%= csrf_meta_tag %&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;container&gt;
        &lt;%= render "shared/nav" %&gt;
        &lt;section id="content"&gt;
          &lt;%- flash.each do |name, msg| -%&gt;
            &lt;%= content_tag :div, msg, :id =&gt; "flash_#{name}" %&gt;
          &lt;%- end -%&gt;
          &lt;%= yield %&gt;
        &lt;/section&gt;
        &lt;%= render "shared/footer" %&gt;
      &lt;/container&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>posts/index.html.erb:</p>
  
  <pre><code>&lt;div id="posts"&gt;
    &lt;%= render 'posts' %&gt;
  &lt;/div&gt;
  &lt;%= will_paginate @posts, :previous_label =&gt; "previous", :next_label =&gt; "next" %&gt;
  &lt;div id="form"&gt;
    &lt;%= render 'form' %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>posts/_posts.html.erb:</p>
  
  <pre><code>&lt;%- for post in @posts -%&gt;
     ...
  &lt;%- end -%&gt;
  </code></pre>
  
  <p>posts/_form.html.erb:</p>
  
  <pre><code>&lt;%= form_for :post, :remote =&gt; true, :url =&gt; { :controller =&gt; :posts, :action =&gt; "create" } do |f| %&gt;
  
    &lt;%= f.label :title, "title" %&gt;
    &lt;%= f.text_field :title, :placeholder =&gt; "title" %&gt;
  
    &lt;%= f.label :content, "message" %&gt;
    &lt;%= f.text_area :content, :placeholder =&gt; "message" %&gt;
  
    &lt;%= f.submit 'post' %&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p>posts/create.js.erb:</p>
  
  <pre><code>$("#posts").html("&lt;%= escape_javascript(render(:partial =&gt; posts)) %&gt;");
  $("#form").html("&lt;%= escape_javascript(render 'form') %&gt;");
  </code></pre>
  
  <p>posts_controller.rb:</p>
  
  <pre><code>class PostsController &lt; ApplicationController
    before_filter :find_post, :only =&gt; [:show, :edit, :update, :destroy]
    respond_to :html, :js
  
    def index
      @title = "chat"
      @posts = Post.paginate :page =&gt; params[:page], :order =&gt; "updated_at DESC"
      respond_to do |format|
        format.html
        format.js
      end
    end
  
    # ...
  
    def new
      @post = Post.new
      respond_to do |format|
        format.html
        format.js
      end
    end
  
    def create
      @post = Post.new(params[:post])
      respond_to do |format|
        if @post.save
          flash[:notice] = "Created \"#{@post.title}\""
          format.html { redirect_to(posts_url) }
          format.js
            else
          flash[:error] = "Title, tag and message required"
          format.html { redirect_to(posts_url) }
          format.js
        end
      end
    end
  
    # ...
  
    private
  
    def find_post
      @post = Post.find(params[:id])
      @comments = @post.comments
    end
  end
  </code></pre>
  
  <p>I'm using Rails 3.0.0, and Ruby 1.9.2. Not sure what the issue is.</p>