我想呈现div内的动作(例如new_sub_batch)的内容。渲染控制器在div内的动作的html内容
我试图
<div id="newBatch">
<%= render :template => 'new_sub_batch.html.erb' %>
</div>
,但不显示任何内容。
我甚至试过<%= render :action => 'new_sub_batch' %>
..什么都没有。
任何建议?
非常感谢
我想呈现div内的动作(例如new_sub_batch)的内容。渲染控制器在div内的动作的html内容
我试图
<div id="newBatch">
<%= render :template => 'new_sub_batch.html.erb' %>
</div>
,但不显示任何内容。
我甚至试过<%= render :action => 'new_sub_batch' %>
..什么都没有。
任何建议?
非常感谢
尝试文件渲染:你想要什么
<div id="newBatch">
<%= render :file => 'directory/new_sub_batch.html.erb' %>
</div>
是谐音。将这两个视图将使用的通用标记放在一个文件中,并用下划线前缀其名称。然后调用render :partial => 'filename'
,其中filename
是不带下划线的部分的名称。
对于您的情况,您从new_sub_batch.html.erb
中提取的代码可能与您的其他sub_batch
视图在同一目录中的_batch.html.erb
部分中。你会渲染这部分:
render :partial => 'batch'
在Rails3中,您可以简单地使用render 'batch'
。
如果要将变量传递给部分,可以通过:locals
来完成。假设你有你想传递一个@sub_batch
变量,您的通话将是这个样子:
render :partial => 'batch', :locals => { :sub_batch => @sub_batch }
虽然这并不严格回答你的问题,我相信ruby-on-rails
标签内它来解释Rails的更重要方式,而不是帮你做错误的方式。
非常感谢您的建议..cheers – keli 2011-06-10 09:11:19