条件存在数组id,其中id为rails

时间:2016-09-06 10:25:56

标签: ruby-on-rails

我有疑问:

Product.all.where(x: @id)

使用

x = ["9", "8", "7","5"] # Array exam

# And 

@id = 5 

如何检查5中是否有array

1 个答案:

答案 0 :(得分:0)

x = [9,8,7,5] #Array测试

@id = 5

if x.include?(@id)
 Product.find(@id)
end

Product.find(@id) if x.include?(@id)