Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在globalize中使用pg_搜索?_Ruby On Rails_Search_Internationalization_Pg Search_Globalize - Fatal编程技术网

Ruby on rails 如何在globalize中使用pg_搜索?

Ruby on rails 如何在globalize中使用pg_搜索?,ruby-on-rails,search,internationalization,pg-search,globalize,Ruby On Rails,Search,Internationalization,Pg Search,Globalize,我在rails应用程序中使用pg_搜索宝石进行搜索。我应用程序中的主要型号是: class Book < ActiveRecord::Base include PgSearch pg_search_scope :search_everywhere, against: [:author, :title, :description] end 在控制器的索引操作中。然后我添加了gem“globalize”: translates :title, :author, :publishe

我在rails应用程序中使用pg_搜索宝石进行搜索。我应用程序中的主要型号是:

class Book < ActiveRecord::Base
  include PgSearch
  pg_search_scope :search_everywhere, against: [:author, :title, :description]
end
在控制器的索引操作中。然后我添加了gem“globalize”:

  translates :title, :author, :publisher, :description, :fallbacks_for_empty_translations => true
现在搜索不起作用了

Book.search_everywhere(params[:search])
找不到任何字段。
有人使用pg_search gem和globalize gem吗?

我找到了正确的解决方案: Gem“globalize”创建了新的table book_翻译。所以我应该在这个表中搜索:

#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

不工作-这意味着什么???到处搜索找不到任何字段。
#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