如何解决担架和法拉第宝石遇到的这些问题?



在我的本地机器上,我使用elasticsearch, ruby, 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

感谢所有的帮助。

当我安装stretcher时,它默认安装faraday_middleware-multi_json 0.0.6和faraday_middleware 0.9.1。

我想我们很多人都面临着这个问题,但我还没有找到一个地方可以让你得到适当的指导。

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

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

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

2。打开lib/stretch .rb

添加一行: require 'multi_json' # line 5

删除这些行:

require 'faraday_middleware/multi_json' # line 7

Faraday.load_autoloaded_constants  # line 8

3。打开 lib/担架/server.rb

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

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

builder.request :multi_json

builder.request :json # line 11

4。打开spec/lib/stretcher_index_spec.rbchange #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。打开担架 change #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")

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

选项:1)使用先前版本的Faraday,例如Gemfile,并带有:

 gem 'faraday', '0.8.9'

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

使用此叉/sha担架:https://github.com/whatstherub/stretcher/commit/b09bce05e3ed07d47ab2a408e2ef674738dc8b28

最新更新