排除数组中的特定对象

时间:2016-10-02 16:55:12

标签: ruby-on-rails arrays json ruby-on-rails-5

我不需要在数组中包含特定对象。

Product有很多line_items

控制器:

[...]

# example line_item Table
line_items = [
  {id: 1, name: "Static Name", ...},
  {id: 2, name: "Other name", ...}
]

@products = Product.order(created_at: :desc).where(domain: @shop.domain).as_json(
  include: {
    line_items: {
      only: [:quantiy, :unit_amount]
    }
  }
)

[...]

如何不包含名称为Static Name的哈希?该名称将始终命名。我需要其他物品。

0 个答案:

没有答案