title: AJAX call to render partial in Rails 3
body: <p>I have a user's dashboard page where the left side has a sidebar with links like Projects, Blogs, etc. I want to be able to click a link such as the "Projects" link and then in the main area, the view for projects would load up (view would be a bullet list of projects) without having to refresh the page. I'm trying to make this happen with AJAX, but things are not working.</p>
  
  <p>Here's how I think it's supposed to work. The user clicks on the sidebar link in <code>show.html.erb</code></p>
  
  <pre><code>&lt;%= link_to 'Projects', '/dash', remote: true %&gt;
  </code></pre>
  
  <p>where <code>/dash</code> is configured to route to users#show in the <code>config/routes.rb</code> file like this:</p>
  
  <pre><code>match '/dash' =&gt; 'users#show'
  </code></pre>
  
  <p>And then, the <code>show</code> action is called in<code>users_controller.rb</code> controller:</p>
  
  <pre><code>def show
      @user = User.find(params[:id])
      @projects = @user.projects
  
      respond_to do |format|
        format.html # renders show.html.erb
        format.js   # renders show.js.erb
      end
  end
  </code></pre>
  
  <p>Where <code>show.js.erb</code> is executed. My <code>show.js.erb</code> file has this one line:</p>
  
  <pre><code>$('#ajax').html("&lt;%= escape_javascript(render(:partial =&gt; 'projects/index')).html_safe %&gt;");
  </code></pre>
  
  <p>And that is supposed to modify the #ajax div in my <code>show.html.erb</code>:</p>
  
  <pre><code>&lt;div id="ajax"&gt;
    &lt;%= render :template =&gt; 'projects/index' %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The <code>app/views/projects/index.html.rb</code> takes in @projects and gives a list, like this:</p>
  
  <pre><code>&lt;% @projects.each do |project| %&gt;
    &lt;p&gt;&lt;%= project.name %&gt;&lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Obviously, I'm doing things wrong because this is not working. What am I doing wrong? Is there some code I need to change elsewhere? I'm on Rails 3.2.13, so the lines <code>//=jquery</code> and <code>//=jquery_ujs</code> under <code>app/assets/javascripts/application.js</code> should have imported the necessary jQuery and AJAX functionality.</p>