1

在我的本地机器上,我正在使用elasticsearch,ruby和gem。sinatrastretcher

我收到以下错误:

faraday.rb:99:in `method_missing': undefined method `load_autoloaded_constants' for #<Faraday::Connection:0x9b9f218> (NoMethodError)

截断的 ruby​​ 代码是:

require 'sinatra'
require 'stretcher'

configure do
  ES = Stretcher::Server.new('http://localhost:9200')
end

class Products
  def self.match(text)
    ES.index(:products).search size: 1000, query: {
      multi_match: { query: text, fields: [:title, :description] }
    }
  end
end

get "/" do
  erb :index
end

get "/:search" do
  erb :result, locals: { products: Products.match(params[:search]) }
end

post "/" do
  unless ES.index(:products).exists?
    # create index if not exists
    ES.index(:products).create(mappings: {
      product: {
        properties: {
          title: {type: :string},
          price: {type: :integer},
          description: {type: :string}
        }
      }
    })
  end

感谢所有帮助。

当我安装担架时,它默认安装 faraday_middleware-multi_json 0.0.6 和 faraday 0.9.0 和 faraday_middleware 0.9.1。

4

3 回答 3

2

我认为我们中的许多人都面临这个问题,但我还没有找到一个地方可以让您获得适当的指示。

解决“法拉第方法缺失:load_autoloaded_constants ”错误的步骤

1.进入命令行,打开gems文件夹下的stretcher文件夹

sudo subl /home/abhinay/.rvm/gems/ruby-2.1.1/gems/stretcher-1.21.1/

2.打开 lib/stretcher.rb

添加这一行: require 'multi_json' # 第 5 行

删除这些行:

require 'faraday_middleware/multi_json'# 第 7 行

Faraday.load_autoloaded_constants  # line 8

3.打开lib/stretcher/server.rb

改变

builder.response :multi_json, :content_type => /\bjson$/ #line 9

builder.response :json, :content_type => /\bjson$/

builder.request :multi_json

builder.request :json# 第 11 行

4.打开spec/lib/stretcher_index_spec.rb 更改#line 44

block.call.should == %{curl -XPUT 'http://localhost:9200/foo' -d '#{MultiJson.dump(options)}' '-H Accept: application/json' '-H Content-Type: application/json' '-H User-Agent: Stretcher Ruby Gem #{Stretcher::VERSION}'}

block.call.should == %{curl -XPUT 'http://localhost:9200/foo' -d '#{JSON.dump(options)}' '-H Accept: application/json' '-H Content-Type: application/json' '-H User-Agent: Stretcher Ruby Gem #{Stretcher::VERSION}'}

5.打开stretcher.gemspec更改#line 30

gem.add_dependency('faraday_middleware', '~> 0.9.0')

gem.add_dependency('faraday_middleware', '~> 0.9')

并删除这些行 # line 33 & 34

gem.add_dependency('multi_json', '>= 1.0')
gem.add_dependency('faraday_middleware-multi_json', "~> 0.0.5")
于 2014-08-19T10:39:17.637 回答
1

我相信这是一个已知的担架问题。参考https://github.com/PoseBiz/stretcher/pull/85

选项: 1) 使用之前版本的法拉第,例如Gemfile

 gem 'faraday', '0.8.9'

2) 镜像更改以解决已知的 Stretcher 问题 85。

于 2014-06-18T19:06:45.073 回答
0

使用这个叉子/担架:https ://github.com/whatstherub/stretcher/commit/b09bce05e3ed07d47ab2a408e2ef674738dc8b28

于 2016-01-12T23:08:28.630 回答