我试图多次渲染相同的局部视图,但它只渲染此集合中的最后一个部分。我缺少什么来渲染每一个?
<ul class="hours">
<%=
Time.use_zone(@place.timezone) do
render partial: 'places/place_hours', locals: { :timezone => @place.timezone, :open => @place.monday_open, :close => @place.monday_close, :day => 'Monday', :is_today => Time.now.in_time_zone.monday? }
render partial: 'places/place_hours', locals: { :timezone => @place.timezone, :open => @place.tuesday_open, :close => @place.tuesday_close, :day => 'Tuesday', :is_today => Time.now.in_time_zone.tuesday? }
render partial: 'places/place_hours', locals: { :timezone => @place.timezone, :open => @place.wednesday_open, :close => @place.wednesday_close, :day => 'Wednesday', :is_today => Time.now.in_time_zone.wednesday? }
render partial: 'places/place_hours', locals: { :timezone => @place.timezone, :open => @place.thursday_open, :close => @place.thursday_close, :day => 'Thursday', :is_today => Time.now.in_time_zone.thursday? }
render partial: 'places/place_hours', locals: { :timezone => @place.timezone, :open => @place.friday_open, :close => @place.friday_close, :day => 'Friday', :is_today => Time.now.in_time_zone.friday? }
render partial: 'places/place_hours', locals: { :timezone => @place.timezone, :open => @place.saturday_open, :close => @place.saturday_close, :day => 'Saturday', :is_today => Time.now.in_time_zone.saturday? }
render partial: 'places/place_hours', locals: { :timezone => @place.timezone, :open => @place.sunday_open, :close => @place.sunday_close, :day => 'Sunday', :is_today => Time.now.in_time_zone.sunday? }
end
%>
</ul>
结果:
周日:关闭预期:
星期一:上午10:00 - 下午7:00
周二:上午10:00 - 下午7:00 周三:上午10:00 - 下午7:00 周四:上午10:00 - 下午7:00星期五:上午10:00 - 下午7:00
星期六:上午10:00 - 下午7:00 周日:关闭答案 0 :(得分:0)
结束了解决方案,但如果问题有答案仍然很好奇。
<ul class="hours">
<%=
place_vars = [
{ :timezone => @place.timezone, :open => @place.monday_open, :close => @place.monday_close, :day => 'Monday', :is_today => Time.now.in_time_zone.monday? },
{ :timezone => @place.timezone, :open => @place.tuesday_open, :close => @place.tuesday_close, :day => 'Tuesday', :is_today => Time.now.in_time_zone.tuesday? },
{ :timezone => @place.timezone, :open => @place.wednesday_open, :close => @place.wednesday_close, :day => 'Wednesday', :is_today => Time.now.in_time_zone.wednesday? },
{ :timezone => @place.timezone, :open => @place.thursday_open, :close => @place.thursday_close, :day => 'Thursday', :is_today => Time.now.in_time_zone.thursday? },
{ :timezone => @place.timezone, :open => @place.friday_open, :close => @place.friday_close, :day => 'Friday', :is_today => Time.now.in_time_zone.friday? },
{ :timezone => @place.timezone, :open => @place.saturday_open, :close => @place.saturday_close, :day => 'Saturday', :is_today => Time.now.in_time_zone.saturday? },
{ :timezone => @place.timezone, :open => @place.sunday_open, :close => @place.sunday_close, :day => 'Sunday', :is_today => Time.now.in_time_zone.sunday? }
]
Time.use_zone(@place.timezone) do
render partial: 'places/place_hours', locals: { :place_vars => place_vars }
end
%>
</ul>
然后每个循环遍历部分以显示内容。