1

On my local machine, I am using elasticsearch, ruby, sinatra and the stretcher gem.

I get the following error:

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

The truncated ruby code is:

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

All help gratefully received.

When I install stretcher it installs faraday_middleware-multi_json 0.0.6 and faraday 0.9.0 and faraday_middleware 0.9.1 by default.

Peter Souter
  • 5,110
  • 1
  • 33
  • 62
user1903663
  • 1,713
  • 2
  • 22
  • 44

3 Answers3

2

I think many of us are facing this issue but I haven't found a single place where you will get a proper instructions.

Steps to resolve "faraday method missing: load_autoloaded_constants" error

1. go to command line and open stretcher folder under gems folder

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

2. Open lib/stretcher.rb

Add this line: require 'multi_json' # line 5

Remove these line:

require 'faraday_middleware/multi_json' # line 7

Faraday.load_autoloaded_constants  # line 8

3. Open lib/stretcher/server.rb

change

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

to

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

and

builder.request :multi_json

to

builder.request :json # line 11

4. Open spec/lib/stretcher_index_spec.rb change #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}'}

to

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. Open stretcher.gemspec change #line 30

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

to

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

and Remove these lines # line 33 & 34

gem.add_dependency('multi_json', '>= 1.0')
gem.add_dependency('faraday_middleware-multi_json', "~> 0.0.5")
Abhinay
  • 1,796
  • 4
  • 28
  • 52
1

I believe this is a known Stretcher issue. Refer to https://github.com/PoseBiz/stretcher/pull/85

Options: 1) Use the prior version of Faraday, e.g. Gemfile with:

 gem 'faraday', '0.8.9'

2) Mirror the changes to address known Stretcher issue 85.

Tombart
  • 30,520
  • 16
  • 123
  • 136
charlez
  • 669
  • 4
  • 6
0

Use this fork/sha of stretcher: https://github.com/whatstherub/stretcher/commit/b09bce05e3ed07d47ab2a408e2ef674738dc8b28

court3nay
  • 2,215
  • 1
  • 10
  • 15