English 中文(简体)
用铁轨中的刺杀电话进行部分观察
原标题:Rendering partial views with ajax calls in rails 3.1

I m starting now with rails, and i have simply question i think. I need to render two partials in one ajax call:

我有以下控制器:

# 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

以及相应的模板(show.js.erb):

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

和名为 _host.html.erb 的部分文件

All this works fine. The template "_host.html.erb" is rendered in div tabs-1, but now i need to add some other partial template in a different id (#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 call a different one like _host2.html.erb and have the same @host instance available?

Thanks, Joao

最佳回答
$( #tabs-1 ).html("<%= j(render @host) %>");
$( #tabs-2 ).html("<%= j(render :partial =>  host2 , :locals => { :host => @host }) %>");
问题回答

暂无回答




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签