ruby on rails - PostgreSQL full-text search: how do i scope it? -
mostly based on railscasts screencasts, #341.
i'm trying use postgresql full text search, , works, need scope it. search should go through objects object.state=='saved'
.
in screencasts method search defined class method, can't use 'where' because 'where' returns array, , search method class method, error here. tried change way:
def test_search(query) if query.present? self.where("title @@ :q or text_for_test @@ :q", q:query) else scoped end end
to:
@tests=test.where(:state=>'saved') @tests.test_search(params[:query])
but rails throws undefined method error.
what else can scope search? or how fix error of attempt?
use textacular gem gives full-text search postgres.
you can use "basic_search" function given textacular similar how use named scopes.
test.basic_search('sonic').where(:status => 'saved') test.where(:status => 'saved').basic_search('sonic')