1

我所拥有的: 几个相同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行不通。我如何将所有本地人链接到下一个部分?

4

1 回答 1

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} %>
于 2012-07-04T18:05:27.330 回答