Sunspot_Rails - 未定义的方法“可搜索”;在页面上
我有一个带有 searchable
块的模型,如下所示:
class Contact < ActiveRecord::Base
searchable do
text :contact_name, :company_name, :contact_email
end
end
在控制器的 index
操作中,我调用 Contact.new
,它给出当前正在我们的临时服务器上运行的页面上出现错误消息:
#
的未定义方法“可搜索”
堆栈跟踪通过控制器中的 Contact.new
行指向模型中的 searchable
块。
当我在本地(在网页或控制台上,或者通过临时服务器上的控制台)运行代码时,不会出现此错误 - 仅在临时网页上出现。
Solr服务在Staging服务器上运行良好,并且数据已成功建立索引。任何关于为什么它在Staging中不起作用的理论都将被接受。
编辑
为了回答下面尼克的问题,Gemfile只有这一行Sunspot:gem 'sunspot_rails'
对于Gemfile.lock,这些是我可以发现的包含Sunspot的所有行或 Solr 参考:
GEM
rsolr (0.12.1)
builder (>= 2.1.2)
sunspot (1.2.1)
escape (= 0.0.4)
pr_geohash (~> 1.0)
rsolr (= 0.12.1)
sunspot_rails (1.2.1)
nokogiri
sunspot (= 1.2.1)
DEPENDENCIES
sunspot_rails
I have a model with a searchable
block, like so:
class Contact < ActiveRecord::Base
searchable do
text :contact_name, :company_name, :contact_email
end
end
In the controller's index
action, I'm calling Contact.new
, which is giving me an error message on the page, which is currently running on our Staging server:
undefined method `searchable' for #<Class:0xce0bf80>
The stack trace is pointing to the searchable
block in the Model via the Contact.new
line in the controller.
When I run the code locally, either on the webpage or the console, or through the console on the Staging server, this error isn't appearing - only on the Staging webpage.
The Solr service is running fine on the Staging server, and the data has been indexed successfully. Any theories as to why it's not playing ball in Staging will be accepted.
EDIT
In response to Nick's question below, the Gemfile just has this line for Sunspot: gem 'sunspot_rails'
For Gemfile.lock, these are all the lines I could spot containing Sunspot or Solr references:
GEM
rsolr (0.12.1)
builder (>= 2.1.2)
sunspot (1.2.1)
escape (= 0.0.4)
pr_geohash (~> 1.0)
rsolr (= 0.12.1)
sunspot_rails (1.2.1)
nokogiri
sunspot (= 1.2.1)
DEPENDENCIES
sunspot_rails
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我遇到了同样的问题,我只需要重新启动我的 Rails 服务器即可。简单的解决方案,但如果不是另一篇文章建议我这样做,我可能会在尝试重新启动服务器之前尝试更长时间地调试错误,呵呵...
I had the same problem, and I just had to restart my rails server. Simple solution, but if it wasn't for another post somewhere that suggested I do so, I would probably have tried to debug the error for a much longer time before just trying to restart the server, hehe...
如果您在安装新的 sunspot gem 后忘记重新启动 Rails 服务器,也可能会发生这种情况
This can also happen if you forget to restart your rails server after installing the new sunspot gem
在我看来,宝石没有正确加载到您的暂存站点上。如果您可以显示 Gemfile 和 Gemfile.lock 的相关部分,我可以更新更多答案。
编辑 — Gemfile 看起来不错。抱歉,如果我无法使用该应用程序,我就一无所获。向太阳黑子邮件列表报告错误? http://outoftime.github.com/sunspot
Sounds to me like the gem isn't being loaded correctly on your staging site. If you can show the relevant sections of your Gemfile and Gemfile.lock, I can update with more of an answer.
EDIT — Gemfile looks fine. Sorry, but I've got nothin' without being able to get my hands on the app. Report a bug to the Sunspot mailing list? http://outoftime.github.com/sunspot
阅读这篇文章
我知道问题是因为 rake 任务行阻止了 Sunspot 的加载
我设法通过以下方式解决它:
我从 Rakefile 中删除了以下行
需要 'sunspot/rails/tasks'
我创建了一个 sunspot.rake 文件,并向其中添加了来自 sunspot gem 源的以下文件的内容:
/gems/sunspot_rails-1.2.1/lib/sunspot/rails/tasks.rb
我知道这是一个 hack,但它正在工作。
After reading this post
I understood that the problem is because the rake tasks line prevents the loading of Sunspot
I managed to solve it in the following way:
I removed the following line from my Rakefile
require 'sunspot/rails/tasks'
I created a sunspot.rake file and added to it the contents of the following file from the sunspot gem source:
/gems/sunspot_rails-1.2.1/lib/sunspot/rails/tasks.rb
I know that this a hack, but it is working.
我刚刚运行了
spring stop
并修复了它I just ran
spring stop
and it fixed it