[英]unable to render more than one partial with jbuilder
我创建了一个控制器函数来获取三个不同模型的所有元素。 就这么简单:
def get_all_data
@events = Event.all
@activities = Activity.all
@places = Place.all
end
然后在get_all_data.json中:
json.partial! 'event', collection: @events
json.partial! 'activity', collection: @activities
json.partial! 'place', collection: @places
问题在于它只渲染一个局部,最后一个。 我想念什么吗? 可以用更好的方法做到吗?
尝试将它们分别放入JSON结构的自己的成员中:
json.event do
json.partial! 'event', collection: @events
end
json.activity do
json.partial! 'activity', collection: @activities
end
json.place do
json.partial! 'place', collection: @places
end
我觉得那应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.