Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 条件存在rails中id为的数组id_Ruby On Rails - Fatal编程技术网

Ruby on rails 条件存在rails中id为的数组id

Ruby on rails 条件存在rails中id为的数组id,ruby-on-rails,Ruby On Rails,我有疑问: Product.all.where(x: @id) 与 如何检查5是否在array中?x=[9,8,7,5]#array检查 @id=5 if x.include?(@id) Product.find(@id) end 或 Product.find(@id)if x.include?(@id)我不明白你在问什么。产品与数组的关系如何?常见查询:product.all.where(id:xxxx)with:xxxx是数组。但在这种情况下,反向查询xxxx更改为id,id更改为xx

我有疑问:

Product.all.where(x: @id)

如何检查
5
是否在
array
中?

x=[9,8,7,5]#array检查

@id=5

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


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

我不明白你在问什么。产品与数组的关系如何?常见查询:product.all.where(id:xxxx)with:xxxx是数组。但在这种情况下,反向查询xxxx更改为id,id更改为xxxxI仍然不理解您的意思,不存在“反向”查询。如果您有id,只需对id执行
Product.find(@id)
Product.find(@id)。在本例中,Product.find_by_目录或Product.where(x:@idx)
if x.include?(@id)
 Product.find(@id)
end