sunspot_solr の使用に関連する問題があります。この宝石を使用していくつかの検索を実行するアプリケーションがあります。この機能を持つモデルは 5 つありますが、エラーが表示されるのはそのうちの 1 つだけです。
@search.results
NoMethodError (undefined method `result=' for nil:NilClass):
app/controllers/financial_dashboards_controller.rb:27:in `index'
これが私のコードです:
コントローラ
@search = Sunspot.search(Purchase) do
fulltext params[:search]
with(:product_owner).equal_to(current_user.id)
facet(:status)
if params[:status].present?
with(:status).equal_to(params[:status])
end
facet(:sell_date)
if params[:sell_date].present?
with(:sell_date).equal_to(params[:sell_date])
end
order_by(:sell_date, :desc)
end
#line 27
@sales = @search.results.paginate(:page => params[:page], :per_page => 5)
モデル (購入):
searchable do
text :product_name
text :product_short_description
integer :product_owner
string :status
string :sell_date
end
def product_name
product.name
end
def product_short_description
product.short_description
end
def product_owner
product.user.id
end
def sell_date
date.to_s(:year_month)
end
#indicates status of the payment and delivery
def status()
if !self.closed.nil?
I18n.t('purchases.status.finished')
elsif !self.measured.nil?
I18n.t('purchases.status.measured')
elsif !self.accomplished.nil?
I18n.t('purchases.status.delivered')
elsif !self.paid.nil?
I18n.t('purchases.status.paid')
elsif !self.canceled.nil?
I18n.t('purchases.status.canceled')
elsif !self.date.nil?
I18n.t('purchases.status.waiting_payment')
end
end
もう 1 つの奇妙な点は、私の開発マシンでは、このコードが完全に機能することです。nginx を使用する実稼働マシンでは、コードにこのエラーが表示されます。
gems のバージョンを確認したところ、一致しました。私は試した
rake sunspot:solr:reindex RAILS_ENV=production
インデックスを再作成します。私は試した
rake sunspot:solr:stop RAILS_ENV=production
rake sunspot:solr:start RAILS_ENV=production
検索サーバーを再起動します。solr/ フォルダーを削除して、開始スクリプトに再度コピーさせようとしました。
そして、他のモデルが完璧に機能するのはなぜですか? これを解決する方法はありますか?
ありがとう