title: Rails: Rendering Partials through Ajax
body: <p>I have a page with tabs and I want to just render different partials through ajax when the tabs are clicked upon. I have some code but I don't think it is the most efficient way. I was hoping if anyone can help me with my code that is already in place or if there is an easier method I would appreciate it a lot. Thank you!</p>
  
  <p><strong>HTML Tab</strong></p>
  
  <pre><code>&lt;li class='StreamTab StreamTabRecent active'&gt;
  &lt;%= link_to 'Most Recent', mostrecent_schools_path, :remote =&gt; true, :class =&gt; 'TabText' %&gt;
  &lt;/li&gt;
  
  
  &lt;div id='ContentBody'&gt;
  &lt;div id='ajax'&gt;&lt;/div&gt;
  &lt;%= render 'users/microposts', :microposts =&gt; @microposts %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>School Controller</strong></p>
  
  <pre><code>class SchoolsController &lt; ApplicationController  
    def mostrecent
      @school = School.find_by_slug(request.url.gsub('http://localhost:3000/','')).id
      @microposts = @user.microposts.order('created_at DESC').paginate(:per_page =&gt; 3, :page =&gt; params[:page])
       respond_to do |format|
        format.html
        format.js
       end
    end
  end
  </code></pre>
  
  <p><strong>Most Recent JS</strong></p>
  
  <pre><code>$("#ContentBody").html('&lt;%= escape_javascript(render :partial =&gt; "users/microposts" )%&gt;');
  </code></pre>
  
  <p><strong>Routes</strong></p>
  
  <pre><code>  resources :schools do
      collection do
          get :mostrecent
      end
    end
  </code></pre>