Partial representations using ajax calls in rails 3.1

Now I'm starting with the rails, and I'm just asking what I think. I need to display two partial elements in one ajax call:

I have the following controller:

# GET /hosts/1
# GET /hosts/1.json
def show
   @host = Host.find(params[:id])

   respond_to do |format|
      format.html #show.html
      format.js
      format.json { render :json => @host }
   end
end

And the corresponding template (show.js.erb):

$('#tabs-1').html("<%= escape_javascript(render @host) %>");

And a partial file called _host.html.erb

It all works great. The template "_host.html.erb" is displayed on div-1 tabs, but now I need to add another partial template to a different identifier (# tabs-2), but use the same @host How can I do this? by default, the render @host method will use the template file "_host.html.erb". How can I name another, for example _host2.html.erb, and have the same @host instance?

Thanks Joao

+3
source share
1 answer
$('#tabs-1').html("<%= j(render @host) %>");
$('#tabs-2').html("<%= j(render :partial => 'host2', :locals => { :host => @host }) %>");
+8
source

All Articles