How to perform a search using pg search gem for a field that is assoicatied through another table?

220 views Asked by At

I have a table called user and I just created a tagging system, where users can have tags through another table. Same way this rail cast does it for it's Books and Authors.

Now I have a search already which is based this way:

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

if I don't have a field inside the user table to search for it, any one can suggest me a join search ? I just can't figure out the syntax with pg_search

1

There are 1 answers

0
0bserver07 On

There is a Gem called Texticle , and here is an awesome Railscast about it! Check it out! It does the job well!