在 Rails 中渲染集合时可以传递额外的变量吗?
Can you pass extra variables when rendering a collection in Rails?
我在最近的项目中经常使用这种模式:
<%= render partial: 'path/to/partial', collection: @crowd, as: :person %>
我想知道是否可以使用相同的语法设置另一个局部变量(而不是例如回退到显式 @crowd.each
循环),这样它看起来像这样:
<%= render partial: 'path/to/partial', collection: @crowd, as: :person, day: 'Thursday' %>
(上面没有错,只是没有在相关部分赋值day
)
有 locals
个:
render partial: 'some_partial', collection: @collection, as: :item_name, locals: { variable_name: 'value', other_variable: 123 }
我在最近的项目中经常使用这种模式:
<%= render partial: 'path/to/partial', collection: @crowd, as: :person %>
我想知道是否可以使用相同的语法设置另一个局部变量(而不是例如回退到显式 @crowd.each
循环),这样它看起来像这样:
<%= render partial: 'path/to/partial', collection: @crowd, as: :person, day: 'Thursday' %>
(上面没有错,只是没有在相关部分赋值day
)
有 locals
个:
render partial: 'some_partial', collection: @collection, as: :item_name, locals: { variable_name: 'value', other_variable: 123 }