Ruby on rails 如何在globalize中使用pg_搜索?
我在rails应用程序中使用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
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