所以我从两个外部服务获取数据:
@list = ExternalService.get_list
ids = @list.map { |member| meber.id }
insurances = ExternalService2.get_insurance
# Get insurance information for each of the ids.
@coverages = insurances.map { |insurance| InsurancePresenter.new(insurance) }
/ In the view
- @list.each do |member|
%tbody
%tr
%td= member.name
%td= member.age
/ This is the part where I need to get information from the other service
%td
- @coverages.each |coverage|
/ method name from the presenter
= coverage.name
很明显,我的代码的最后一部分是不正确的,因为它会打印每行的所有coverage。
我想知道是否有一种快速的方法来组合2并在应用程序中显示它们。 如果是数据库请求,那将是一个简单的连接。
答案 0 :(得分:0)
最简单的方法是为每个成员开始计数和迭代,并使用计数显示coverages数组中的每个coverage。抱歉,不知道HAML,但这是一般的想法。
/在视图中
count = -1
- @list.each do |member|
%tbody
%tr
%td= member.name
%td= member.age
count+=1
/ This is the part where I need to get information from the other service
%td
- @coverages[count].name