2013-12-17 25 views
0

我有一個叫做用戶的表格,我剛剛創建了一個標記系統,用戶可以通過另一個表格添加標籤。 Same way this rail cast does it for it's Books and Authors.如何使用pg search gem搜索通過另一個表關聯的字段進行搜索?

現在我已經搜索是基於這樣:

def self.text_search(query) 
    if query.present? 
     where("first_name @@ :q OR last_name @@ :q OR country @@ :q OR (first_name || ' ' || last_name) @@ :q", :q => query) 
    else 
     scoped 
    end 
    end 

,如果我沒有在user表中的字段進行搜索,任何一個可以建議我加入搜索? 我只是不知道與pg_search語法

回答

相關問題