Ora*_*nge 3 ajax renderpartial ruby-on-rails erb ruby-on-rails-3.1
我现在开始使用rails,我只想问一下.我需要在一个ajax调用中呈现两个部分:
我有以下控制器:
# 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
Run Code Online (Sandbox Code Playgroud)
和相应的模板(show.js.erb):
$('#tabs-1').html("<%= escape_javascript(render @host) %>");
Run Code Online (Sandbox Code Playgroud)
还有一个名为_host.html.erb的部分文件
这一切都很好.模板"_host.html.erb"在div tabs-1中呈现,但现在我需要在不同的id(#tabs-2)中添加一些其他部分模板,但是使用相同的@host我该怎么做?默认情况下,render @host方法将使用模板文件"_host.html.erb".我如何调用另一个像_host2.html.erb并具有相同的@host实例?
谢谢,Joao
$('#tabs-1').html("<%= j(render @host) %>");
$('#tabs-2').html("<%= j(render :partial => 'host2', :locals => { :host => @host }) %>");
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4207 次 |
最近记录: |