将本地人传送到更深的部分

时间:2012-07-04 17:28:56

标签: ruby-on-rails ruby ruby-on-rails-3

我有什么: 对同一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不起作用。如何将所有本地人链接到下一个部分?

1 个答案:

答案 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} %>