2016-01-21 50 views
0

我試圖使用搜查,但有問題,當我試圖檢索ID和串在一起,就像洗劫搜索ID和字符串連接在一起

:id_or_title_or_user_username_cont

它產生錯誤

ActionView::Template::Error (PG::UndefinedFunction: ERROR: operator does not exist: integer ~~* integer

我要搜索也試過這種

:id_eq_or_title_or_user_username_cont

它產生以下錯誤

undefined method `id_eq_or_title_or_user_username_cont' for Ransack::Search

使用搜索引擎而不是自定義謂詞或自定義謂詞,搜索id和字符串的適當方法是什麼?

回答

0
ransacker :id_to_s do 
    Arel.sql("regexp_replace(to_char(\"#{table_name}\".\"id\", '9999999'), ' ', '', 'g')") 
end 
+0

感謝您的幫助。我在這裏有點困惑,我想如何在搜索領域使用它?就像我的問題中的謂詞可以用作 <%= f.search_field:id_eq_or_title_or_user_username_cont%> 可以請您詳細說明一下。這將非常感激。在此先感謝 –

+0

所以@FakhirShad如果你感到困惑,那麼你不應該接受這個答案。 –

+0

查看我評論的日期和答案被接受的日期@zozo –