このクラスのget_products_conditions_for
メソッドをオーバーライドする必要があります。これを行う最善の方法は何ですか?lib/spree/search/base.rbをオーバーライドする方法
私は初期にこれを追加しようとしました:
サーバー起動時にこのエラーが発生しSpree::Search::Base.class_eval do
def get_products_conditions_for(base_scope, query)
base_scope.like_any([:name, :description], query.split) | base_scope.joins("JOIN taggings on taggings.taggable_id = spree_products.id JOIN tags on tags.id = taggings.tag_id").where("tags.name = ?", query.split)
end
end
:私もこれを追加しようとしましたuninitialized constant Spree::Search (NameError)
をする「/ libに/まくります/検索/ base.rb」と "/lib/spree/search/tags_search.rb"
module Spree::Search
class TagsSearch < Spree::Search::Base
def get_products_conditions_for(base_scope, query)
base_scope.like_any([:name, :description], query.split) | base_scope.joins("JOIN taggings on taggings.taggable_id = spree_products.id JOIN tags on tags.id = taggings.tag_id").where("tags.name = ?", query.split)
end
end
end
、その後application.rbでSpree::Config.searcher = TagsSearch
...
私も完全に私が何をしようとしている...
をされたアプリ内で同じディレクトリ構造にレプリカを配置することにより、ファイルを交換する、のいずれか何も起こらない、または私が言及したエラーを取得しようとしました...
EDITを行い、働いているacts_as_taggable_on
を統合し、しかし検索は明らかにこれらのタグから結果を返しません: [OK]をので、ステフの答えの後に私が試した:で
module Spree::Search
class TagsSearch < Spree::Search::Base
def get_products_conditions_for(base_scope, query)
base_scope.like_any([:name, :description], query.split) | base_scope.joins("JOIN taggings on taggings.taggable_id = spree_products.id JOIN tags on tags.id = taggings.tag_id").where("tags.name = ?", query.split)
end
end
end
を3210およびlib/spree/search/tags_search.rb
これでステフのコードの提案:私はお勧め
uninitialized constant TagsSearch (NameError)
あなたはどうやってインストールされていますか?宝石?プラグイン?スプレーの読み順のような音が問題です。 – siannopollo
宝石として、それは他の何かのようになるとは思わない... –