我有什么:
对同一partial
但有不同locals
的
<%= render :partial => 'link/to/partial', :locals => {:fieldtype => 'textline', :text => object.text} %>
<%= render :partial => 'link/to/partial', :locals => {:fieldtype => 'list', :list => object.list, :header => 'HEADER'} %>
现在_partial.html.erb
有以下一行:
<%= render :partial => 'link/to/partial/'+fieldtype, :locals => locals %>
我想要的是什么:
显然:locals => locals
不起作用。如何将所有本地人链接到下一个部分?
答案 0 :(得分:0)
为了澄清,您可以将所有本地人放在这样的哈希中:
<% my_locals = {:fieldtype => 'textline', :text => object.text} %>
<%= render :partial => 'link/to/partial', :locals => {:my_locals => my_locals} %>
(并非令人困惑的是{}
都用于声明哈希和块)
在你的部分中,你会这样做:
<%= render :partial => 'link/to/partial/'+my_locals[:fieldtype], :locals => {:my_locals => my_locals} %>