【问题标题】:Undefined local variable or method `searchkick'未定义的局部变量或方法“searchkick”
【发布时间】:2014-05-26 10:25:52
【问题描述】:

我正在尝试将 Searchkick 添加到我的 Rails 应用程序中。我正在遵循Get started page 上的确切说明,但我不断收到以下错误:

Started GET "/airports" for 10.0.2.2 at 2014-05-26 10:20:33 +0000
Processing by AirportsController#index as HTML
Completed 500 Internal Server Error in 26ms

NameError (undefined local variable or method `searchkick' for #<Class:0xb48f3ba8>):
  app/models/airport.rb:2:in `<class:Airport>'
  app/models/airport.rb:1:in `<top (required)>'
  app/controllers/airports_controller.rb:3:in `index'


  Rendered /home/vagrant/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.5ms)
  Rendered /home/vagrant/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.2ms)
  Rendered /home/vagrant/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.9ms)
  Rendered /home/vagrant/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (19.8ms)

Airport 模型如下所示:

# ./app/models/airport.rb
class Airport < ActiveRecord::Base
    searchkick
end

这就是机场控制器的样子:

# ./app/controllers/airports_controller/rb
class AirportsController < ApplicationController
  def index
    @airports = Airport.all
  end
end

这是什么原因造成的?

【问题讨论】:

  • 我觉得很好。你真的在你的机器上安装了searchkick gem吗?
  • 是的,我做到了。我不得不重新启动服务器。现在都在工作。谢谢

标签: ruby-on-rails ruby searchkick


【解决方案1】:

重启服务器。对 Gemfile 进行更改后,必须重新启动服务器。

如果不起作用,您可以尝试其他方法:

  • gem 'searchkick' 添加到 Gemfile
  • bundle install

【讨论】:

  • 我不得不停止 spring 让它为我工作 (spring stop)。其他的尝试。
【解决方案2】:

这里也一样。我检查了gem list,searchkick 在那里。

但我删除了 Gemfile 中的 searchkick 并运行了 bundle install。然后再添加searchkickbundle install,效果很好:)

【讨论】:

    猜你喜欢
    • 2017-01-26
    • 2018-04-19
    • 2015-01-01
    • 2013-12-17
    • 2016-04-29
    • 2018-04-21
    相关资源
    最近更新 更多