0

I use a pg_search gem for searching in my rails app. The main model in my app was:

class Book < ActiveRecord::Base
  include PgSearch
  pg_search_scope :search_everywhere, against: [:author, :title, :description]
end

It worked perfect with

@books = Book.search_everywhere(params[:search])

in index action of BooksController. Then I added gem 'globalize':

  translates :title, :author, :publisher, :description, :fallbacks_for_empty_translations => true

And now searching is not working.

Book.search_everywhere(params[:search])

can't find any field. Anybody used pg_search gem with globalize gem?

Victor
  • 897
  • 8
  • 4

1 Answers1

0

I have found correct solution: Gem 'globalize' created new table "book_translations". So I should search in this table:

#book.rb
class Book < ActiveRecord::Base
  include PgSearch
  has_many :book_translations
  translates :title, :author, :publisher, :description, :fallbacks_for_empty_translations => true
  pg_search_scope :search_everywhere, :associated_against  => {:book_translations => [:title, :author, :description]}
end

#book_translation.rb
class BookTranslation < ActiveRecord::Base
  belongs_to :book
end
Victor
  • 897
  • 8
  • 4