Ruby on rails Algolia未知参数
我正在使用algolia在rails应用程序中使用algolia搜索rails gem进行搜索 在我的产品模型中,我有:Ruby on rails Algolia未知参数,ruby-on-rails,algolia,Ruby On Rails,Algolia,我正在使用algolia在rails应用程序中使用algolia搜索rails gem进行搜索 在我的产品模型中,我有: algoliasearch index_name: "Product" do attributes :id, :name, :description, :active? ... end 我正在尝试使用名为“活动”的筛选器筛选结果。当我尝试运行包含参数的搜索时,Algolia返回了一个错误 {"hits"=>[], "hitsPerPage"=>0, "
algoliasearch index_name: "Product" do
attributes :id, :name, :description, :active?
...
end
我正在尝试使用名为“活动”的筛选器筛选结果。当我尝试运行包含参数的搜索时,Algolia返回了一个错误
{"hits"=>[], "hitsPerPage"=>0, "page"=>0, "facets"=>{}, "error"=>#<Algolia::AlgoliaProtocolError: 400: Cannot POST to https://algolia.net/1/indexes/Product_development/query: {"message":"Unknown parameter: active%3F","status":400}
{“hits”=>[],“hitsPerPage”=>0,“page”=>0,“facets”=>{},“error”=>#您不能使用带有问号的属性
正如Slava.K在评论中提到的,如果您的active?
方法是一个活动记录属性,那么使用active
就可以了
但是,如果active?
是与活动记录无关的方法,我建议添加如下自定义属性:
class Product < ActiveRecord::Base
include AlgoliaSearch
algoliasearch do
attributes :id, :name, :description
attribute :active do
active?
end
end
def active?
...
end
end
类产品
有关自定义属性的更多详细信息,请参见此处:是否使用ActiveRecord?如果是这样,则可能:active?
属性应仅为:active
,因为它在数据库中是如何命名的。:active?
仅为AR提供的布尔字段的别名