gpt4 book ai didi

ruby-on-rails - 查询查询结果错误

转载 作者:行者123 更新时间:2023-12-02 23:03:01 24 4
gpt4 key购买 nike

searchkick查询得到错误的结果。
我在数据库中有一条记录:

2.2.0 :047 > Product.first
#<Product id: 1, title: "Ball", description: "<p>Ball</p>\r\n", price: 10, material: "lalala", created_at: "2015-04-21 04:30:53", updated_at: "2015-04-21 04:30:53", preview: "images__1_.jpg", count: 20>

在 Controller Product和操作 search中,我有以下代码:
    def search
@products = Product.search "*", where:
{
count: 10..18
}
end

然后,得到具有该值的count的获取结果。
但是,在db count = 20的情况下,总是出现错误的结果。不知道为什么

最佳答案

我得到的结果不正确,因为在模型中没有哈希,因此需要重新索引模型。

在模型中:

def search_data
{
count: count,
price: price,
title: title,
category_id: categories.map($:id)
}
end

然后,在Rails控制台中写道:
Product.reindex

关于ruby-on-rails - 查询查询结果错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29765968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com