Rendering Multiple Partials with Ruby on Rails

So, as we speak, I’m going through a bit of the code that I’ve submitted for the OLM project, and I’ve begun refactoring.

While doing this, I ran into an interesting problem:  I want to use Rails’ remote_function to update two sections of the page with an AJAX call.  For a while, this stumped me, because you can really only have one render call within a controller method, like this:

render :partial => "footer"

But I was determined to render two.  So here’s what I ended up doing:

On the client side, I’ve got this in my view…

<%= remote_function (:url =>{ :action => "codeviewer", :id => @assignment.id, :uid => @uid },
                   :with => "'fid='+fid", :after => "$('working').hide();")%>

And in the Controller, in the “codeviewer” method, I do this:

render :update do |page|
    page.replace_html 'codeviewer', :partial => 'codeviewer', :locals =>
        { :uid => params[:uid], :filetext => filetext, :annots => annots}
      #Also update the annotation_summary_list
    page.replace_html 'annotation_summary_list', :partial => 'annotation_summary', :locals => {:annots => annots, :fid => @fid}
end

This will render my two partials in the DOM elements with ID’s ‘codeviewer’ and ‘annotation_summary_list’, respectively.

Nice.