将局部视图从局部视图传递到另一个局部视图

时间:2017-12-14 11:36:22

标签: ruby-on-rails ruby-on-rails-4 erb

我希望将所有传递locals从一个局部视图传递到0-N内部局部视图。

示例:

# my_view.html.erb
<%= render partial: 'my_partial_view', locals: { ...dynamic amount of variables... } %>
...
# _my_partial_view.html.erb
<%= render partial: 'inner_partial_view_A', locals: ??? if ABC %>
<%= render partial: 'inner_partial_view_B', locals: ??? if DEF %>
<%= render partial: 'inner_partial_view_C', locals: ??? if XYZ %>

1 个答案:

答案 0 :(得分:2)

尝试以下

<%= render partial: 'inner_partial_view_A', local_assigns if ABC %>
<%= render partial: 'inner_partial_view_B', local_assigns if DEF %>
<%= render partial: 'inner_partial_view_C', local_assigns if XYZ %>