ruby-on-rails-3 – sunspot_solr – NoMethodError(未定义的方法`result =’代表nil:NilClass)

ruby-on-rails-3 – sunspot_solr – NoMethodError(未定义的方法`result =’代表nil:NilClass),第1张

概述我有一个与使用sunspot_solr有关的问题.我有一个应用程序,使用此gem执行一些搜索.有5个型号具有此功能,其中只有1个显示错误 @search.resultsNoMethodError (undefined method `result=' for nil:NilClass): app/controllers/financial_dashboards_controller.rb: 我有一个与使用sunspot_solr有关的问题.我有一个应用程序,使用此gem执行一些搜索.有5个型号具有此功能,其中只有1个显示错误

@search.resultsNoMethodError (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_dateend         def product_name  product.nameenddef product_short_description  product.short_descriptionenddef product_owner  product.user.IDenddef sell_date  date.to_s(:year_month)end#indicates status of the payment and deliverydef 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')    endend

另一个奇怪的事情是,在我的开发机器上,这段代码完美无缺.在使用Nginx的生产计算机上,代码显示此错误.

我检查了宝石的版本,他们匹配.我试过了

rake sunspot:solr:reindex RAILS_ENV=production

重新索引.我试过了

rake sunspot:solr:stop RAILS_ENV=productionrake sunspot:solr:start RAILS_ENV=production

重新启动搜索服务器.甚至尝试删除solr /文件夹并让启动脚本再次复制它.

为什么其他型号完美运作?任何想法如何解决这个问题?

谢谢

解决方法 就我而言,这是一个关键字段(ID)不唯一的情况.

之所以发生这种情况是因为我设计了一个具有非独特ID字段的MysqL视图.

这就是为什么太阳黑子在下一个非独特行指数化过程中总是“下降”首次命中为零.

所以

hit.result = result

在太阳黑子宝石代码的某个地方引发了一个错误

当我想出来的时候(我已经花了几个小时),我只是让我的ID字段独一无二,重新索引我的模型并且问题已经消失了.

总结

以上是内存溢出为你收集整理的ruby-on-rails-3 – sunspot_solr – NoMethodError(未定义的方法`result =’代表nil:NilClass)全部内容,希望文章能够帮你解决ruby-on-rails-3 – sunspot_solr – NoMethodError(未定义的方法`result =’代表nil:NilClass)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1267797.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存