Rails render partial with :collection

若如初见. 提交于 2019-12-04 01:01:35

This is an old question but just case others are struggling with it

When a partial is called with a pluralized collection, then the individual instances of the partial have access to the member of the collection being rendered via a variable named after the partial.

From http://guides.rubyonrails.org/layouts_and_rendering.html

In the example above from the OP, because the partial was called booking instead of bookings, Rails was failing to infer the member name to be used in the partial, hence the need to pass it explicitly as as: :booking

Your call to render is different than what is shown in the guide. Have you tried render :partial => 'booking', :collection => @bookings?

I believe you should also be able to use the shorter alternative assuming you are in Rails 3 or later: render @bookings.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!