【发布时间】:2014-07-27 03:21:27
【问题描述】:
所以我从两个外部服务获取数据:
@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
显然我的代码的最后一部分是不正确的,因为它会打印每一行的所有覆盖率。
我想知道是否有一种快速的方法可以将两者结合起来并在应用程序中显示它们。 如果它是一个数据库请求,它将是一个简单的连接。
【问题讨论】:
-
覆盖范围和列表是否相关?如果在连接中很容易做到,那么这里可能很容易。只需要一个关联即可。
-
@Swards。它不相关。就像我提到的那样。它没有直接访问数据库。它是给我们返回 json 的外部服务。
-
我明白了 - 这两个外部服务之间有什么关系吗?你怎么知道列表和覆盖范围是相关的?
标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.2 ruby-on-rails-3.1