I have a tabbed page and I just want to render different particles through ajax when clicking on the tabs. I have some code, but I don't think this is the most efficient way. I was hoping that if someone could help me with my code that already exists, or if there is a simpler method, I would really appreciate it. Thanks!
HTML tab
<li class='StreamTab StreamTabRecent active'> <%= link_to 'Most Recent', mostrecent_schools_path, :remote => true, :class => 'TabText' %> </li> <div id='ContentBody'> <div id='ajax'></div> <%= render 'users/microposts', :microposts => @microposts %> </div>
School controller
class SchoolsController < 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 => 3, :page => params[:page]) respond_to do |format| format.html format.js end end end
Latest js
$("#ContentBody").html('<%= escape_javascript(render :partial => "users/microposts" )%>');
Routes
resources :schools do collection do get :mostrecent end end
source share