我正在使用带有标准导轨形式和 Cocoon gem 的 Rails 3。我想使用 gem 提供的 'render_options' 通过 'link_to_add_association' 将变量发送到部分,但我无法使其工作。部分视图渲染正常,coocon 工作正常(可以添加和删除项目),但变量除外。尝试在视图中打印变量表示未定义。这是我的代码:
_form.html.erb(这是从 new.html.erb 调用的部分)
<%= link_to_add_association raw('Nuevo con empleado existente'), f, parte_diario_item_indirectos, :render_options => {:locals => {:foo => 'bar'}}%>
_parte_diario_item_indirecto_fields.html.erb
<%= foo %>
做这样的事情会导致“未定义的'foo'错误”。
我也试过:
<%= locals[:foo] %>
结果相同。在“render_options”周围使用方括号/大括号也不起作用。