我试图弄清楚如何使用 pg_search_gem 和 pg_search_scope 将多个参数传递给我的搜索
这是我的简单搜索
include PgSearch
pg_search_scope :simple_search, against: [:title, :description], using: { tsearch: { dictionary: "spanish"} }
def self.search(search)
if search.present?
simple_search(search)
else
find(:all)
end
end
但现在我正在尝试做这样的事情
include PgSearch
pg_search_scope :simple_search, against: [:title, :place, :category], using: { tsearch: { dictionary: "spanish"} }
def self.searchadv(title, place, category)
simple_search(:title => title, :place => place, :category => category)
end
我知道这是完全错误的,但这是我的调查。
更新
这是新代码
pg_search_scope :advance_search, lambda {|*args, query|
return {:against => args,
:query => query,
using: { tsearch: { dictionary: "spanish"} } }
}
def self.searchadv(query, title, place, category)
advance_search(:all, :title => title, :place => place, :category => category)
end
还是行不通。但它几乎完成了!我收到此错误:
wrong number of arguments (3 for 4)