【问题标题】:Ruby on Rails : How to find a matching value in JSON arrays?Ruby on Rails:如何在 JSON 数组中查找匹配值?
【发布时间】:2015-06-05 17:26:27
【问题描述】:
irb(main):001:0> d = OurDomains.find(3)
=> #<OurDomains:0x000000056ea410 @id="2", @internal_domains=["1.com", "2.com", "3.com"], @external_domains=["2.com"]>

以上面的响应为例,有人可以指导我如何比较 internal_domains 和 external_domains 数组中的值吗?特别是,我有兴趣在我的 view.html.erb 中显示 internal_domains 中与 external_domains 中的值相对应的所有值;在这种情况下是“2.com”

【问题讨论】:

  • 你想要d.internal_domains &amp; d.external_domains 吗? Intersection.

标签: arrays ruby json ruby-on-rails-3 erb


【解决方案1】:
@internal_domains & @external_domains

【讨论】:

  • @user2782109 你可以看到我的评论吗?
  • 截断结果是什么意思?
猜你喜欢
  • 2011-10-28
  • 2019-11-01
  • 1970-01-01
  • 2021-12-30
  • 2018-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-28
相关资源
最近更新 更多