【发布时间】:2019-03-21 12:27:28
【问题描述】:
我在最近的一个项目中经常使用这种模式:
<%= render partial: 'path/to/partial', collection: @crowd, as: :person %>
我想知道是否可以使用相同的语法设置另一个局部变量(而不是使用显式的 @crowd.each 循环),所以它看起来像这样:
<%= render partial: 'path/to/partial', collection: @crowd, as: :person, day: 'Thursday' %>
(以上没有错误,只是没有在相关部分分配day)
【问题讨论】:
-
尝试将
day包装在locals哈希中。locals: { day: 'Thursday' } -
试试:
<%= render partial: 'path/to/partial', collection: @crowd, as: :person, locals: { day: 'Thursday' } %>guides.rubyonrails.org/…