#<Faraday::ConnectionFailed> 连接被拒绝 - 连接(2)

ach*_*s77 6 ruby ruby-on-rails faraday-oauth faraday

#<Faraday::ConnectionFailed> Connection refused - connect(2)我在使用复选框选择项目users/edit.html.erb并按下保存后收到消息。我选择的项目位于名为 的数组中amenities_list。这些项目是布尔值。尝试保存我收到的更改后#<Faraday::ConnectionFailed>

用户/edit.html.erb

<div class="tab-content group">

  <% amenities_list = User.amenities_list %>

  <ul>
    <% @user.boolean_array_from_amenities_integer.each_with_index do |amenity_available,index| %>
      <% if amenity_available %>
        <li class="available-amenity">
      <% else %>
        <li class="unavailable-amenity">
      <% end %>
          <%= amenities_list[index] %>
        </li>
    <% end %>
  </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

用户控制器.rb

  def new
    @user = User.new
  end

  def create
    @user = User.new(params[:user])
    @user.id = current_user.id
    @user.set_amenities_from_options_list!(params[:user_amenities_indicies])
    if @user.save
      flash[:success] = "Thank you for signing up! A confirmation email has been sent to your inbox"
      redirect_to users_path
    else
      render :new
    end
  end

  def edit
    @user.id = current_user.id
    @user.set_amenities_from_options_list!(params[:user_amenities_indicies])
  end
Run Code Online (Sandbox Code Playgroud)

用户.rb

  def self.amenities_list
    ["Smoking Allowed",
     "Pets Allowed",
     "TV",
     "Cable TV",
     "Internet",
     "Wireless Internet",
     "Air Conditioning",
     "Heating",
     "Elevator in Building",
     "Handicap Accessible",
     "Pool",
     "Kitchen",
     "Free parking on premise",
     "Doorman",
     "Gym",
     "Hot Tub",
     "Indoor Fireplace",
     "Buzzer/Wireless Intercom",
     "Breakfast",
     "Family/Kid Friendly",
     "Suitable for Events",
     "Washer",
     "Dryer"]
  end

  def self.integer_from_options_list(options_list)
    # convert options list given by radio buttons into one-hot integer
    amenities = 0;
    if options_list
      options_list.each do |option|
        amenities += 2 ** option.to_i
      end
  end

    amenities
  end

   def self.find_with_filters(filters)
    filtered_users = User
        if filters[:amenities]
          amenities = User.integer_from_options_list(filters[:amenities])
          filtered_users = filtered_users.where("amenities & ? = ?", amenities, amenities)
        end
    end


 def set_amenities_from_options_list!(options_list)
    self.amenities = User.integer_from_options_list(options_list)
  end

    def boolean_array_from_amenities_integer
    [].tap do |amenities_list|
      User.amenities_list.length.times do |order|
        amenities_list << (self.amenities & 2 ** order > 0)
        end
      end
    end

end
Run Code Online (Sandbox Code Playgroud)

gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (4.0.3)
      actionpack (= 4.0.3)
      mail (~> 2.5.4)
    actionpack (4.0.3)
      activesupport (= 4.0.3)
      builder (~> 3.1.0)
      erubis (~> 2.7.0)
      rack (~> 1.5.2)
      rack-test (~> 0.6.2)
    activemodel (4.0.3)
      activesupport (= 4.0.3)
      builder (~> 3.1.0)
    activerecord (4.0.3)
      activemodel (= 4.0.3)
      activerecord-deprecated_finders (~> 1.0.2)
      activesupport (= 4.0.3)
      arel (~> 4.0.0)
    activerecord-deprecated_finders (1.0.3)
    activesupport (4.0.3)
      i18n (~> 0.6, >= 0.6.4)
      minitest (~> 4.2)
      multi_json (~> 1.3)
      thread_safe (~> 0.1)
      tzinfo (~> 0.3.37)
    arel (4.0.2)
    atomic (1.1.16)
    bcrypt (3.1.7)
    bcrypt-ruby (3.1.5)
      bcrypt (>= 3.1.3)
    bootstrap-sass (3.1.1.0)
      sass (~> 3.2)
    builder (3.1.4)
    capybara (2.1.0)
      mime-types (>= 1.16)
      nokogiri (>= 1.3.3)
      rack (>= 1.0.0)
      rack-test (>= 0.5.4)
      xpath (~> 2.0)
    carrierwave (0.10.0)
      activemodel (>= 3.2.0)
      activesupport (>= 3.2.0)
      json (>= 1.7)
      mime-types (>= 1.16)
    childprocess (0.5.1)
      ffi (~> 1.0, >= 1.0.11)
    coderay (1.1.0)
    coffee-rails (4.0.1)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0, < 5.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.7.0)
    columnize (0.3.6)
    debugger (1.6.6)
      columnize (>= 0.3.1)
      debugger-linecache (~> 1.2.0)
      debugger-ruby_core_source (~> 1.3.2)
    debugger-linecache (1.2.0)
    debugger-ruby_core_source (1.3.2)
    diff-lcs (1.2.5)
    elasticsearch (1.0.2)
      elasticsearch-api (= 1.0.2)
      elasticsearch-transport (= 1.0.2)
    elasticsearch-api (1.0.2)
      multi_json
    elasticsearch-model (0.1.4)
      activesupport (> 3)
      elasticsearch (> 0.4)
      hashie
    elasticsearch-transport (1.0.2)
      faraday
      multi_json
    erubis (2.7.0)
    execjs (2.0.2)
    factory_girl (4.2.0)
      activesupport (>= 3.0.0)
    factory_girl_rails (4.2.1)
      factory_girl (~> 4.2.0)
      railties (>= 3.0.0)
    faker (1.3.0)
      i18n (~> 0.5)
    faraday (0.9.0)
      multipart-post (>= 1.2, < 3)
    ffi (1.9.3)
    figaro (0.7.0)
      bundler (~> 1.0)
      rails (>= 3, < 5)
    geocoder (1.1.9)
    hashie (3.0.0)
    hike (1.2.3)
    i18n (0.6.9)
    jbuilder (1.5.3)
      activesupport (>= 3.0.0)
      multi_json (>= 1.2.0)
    jquery-rails (3.1.0)
      railties (>= 3.0, < 5.0)
      thor (>= 0.14, < 2.0)
    jquery-ui-rails (4.2.0)
      railties (>= 3.2.16)
    json (1.8.1)
    jwt (0.1.11)
      multi_json (>= 1.5)
    mail (2.5.4)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    method_source (0.8.2)
    mime-types (1.25.1)
    mini_magick (3.7.0)
      subexec (~> 0.2.1)
    mini_portile (0.5.2)
    minitest (4.7.5)
    multi_json (1.9.0)
    multi_xml (0.5.5)
    multipart-post (2.0.0)
    nokogiri (1.6.1)
      mini_portile (~> 0.5.0)
    oauth (0.4.7)
    oauth2 (0.9.3)
      faraday (>= 0.8, < 0.10)
      jwt (~> 0.1.8)
      multi_json (~> 1.3)
      multi_xml (~> 0.5)
      rack (~> 1.2)
    pg (0.17.1)
    polyglot (0.3.4)
    pry (0.9.12.6)
      coderay (~> 1.0)
      method_source (~> 0.8)
      slop (~> 3.4)
    pry-debugger (0.2.2)
      debugger (~> 1.3)
      pry (~> 0.9.10)
    quiet_assets (1.0.2)
      railties (>= 3.1, < 5.0)
    rack (1.5.2)
    rack-test (0.6.2)
      rack (>= 1.0)
    rails (4.0.3)
      actionmailer (= 4.0.3)
      actionpack (= 4.0.3)
      activerecord (= 4.0.3)
      activesupport (= 4.0.3)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.0.3)
      sprockets-rails (~> 2.0.0)
    rails_12factor (0.0.2)
      rails_serve_static_assets
      rails_stdout_logging
    rails_serve_static_assets (0.0.2)
    rails_stdout_logging (0.0.3)
    railties (4.0.3)
      actionpack (= 4.0.3)
      activesupport (= 4.0.3)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (10.1.1)
    rdoc (4.1.1)
      json (~> 1.4)
    rspec-core (2.13.1)
    rspec-expectations (2.13.0)
      diff-lcs (>= 1.1.3, < 2.0)
    rspec-mocks (2.13.1)
    rspec-rails (2.13.1)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (~> 2.13.0)
      rspec-expectations (~> 2.13.0)
      rspec-mocks (~> 2.13.0)
    rubyzip (0.9.9)
    sass (3.2.15)
    sass-rails (4.0.2)
      railties (>= 4.0.0, < 5.0)
      sass (~> 3.2.0)
      sprockets (~> 2.8, <= 2.11.0)
      sprockets-rails (~> 2.0.0)
    sdoc (0.4.0)
      json (~> 1.8)
      rdoc (~> 4.0, < 5.0)
    selenium-webdriver (2.35.1)
      childprocess (>= 0.2.5)
      multi_json (~> 1.0)
      rubyzip (< 1.0.0)
      websocket (~> 1.0.4)
    simple_form (3.0.1)
      actionpack (>= 4.0.0, < 4.1)
      activemodel (>= 4.0.0, < 4.1)
    slop (3.5.0)
    sorcery (0.8.5)
      bcrypt-ruby (>= 3.0)
      oauth (~> 0.4.4)
      oauth2 (>= 0.8.0, < 1.0.0)
    sprockets (2.11.0)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sprockets-rails (2.0.1)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      sprockets (~> 2.8)
    state_machine (1.2.0)
    subexec (0.2.3)
    thor (0.18.1)
    thread_safe (0.2.0)
      atomic (>= 1.1.7, < 2)
    tilt (1.4.1)
    treetop (1.4.15)
      polyglot
      polyglot (>= 0.3.1)
    tzinfo (0.3.39)
    uglifier (2.5.0)
      execjs (>= 0.3.0)
      json (>= 1.8.0)
    websocket (1.0.7)
    xpath (2.0.0)
      nokogiri (~> 1.3)

PLATFORMS
  ruby

DEPENDENCIES
  bootstrap-sass (~> 3.1.1)
  capybara (= 2.1.0)
  carrierwave
  coffee-rails (~> 4.0.0)
  elasticsearch-model
  factory_girl_rails (= 4.2.1)
  faker
  figaro
  geocoder
  jbuilder (~> 1.2)
  jquery-rails
  jquery-ui-rails
  mini_magick
  pg
  pry-debugger
  quiet_assets
  rails (= 4.0.3)
  rails_12factor
  rspec-rails (= 2.13.1)
  sass-rails (~> 4.0.0)
  sdoc
  selenium-webdriver (= 2.35.1)
  simple_form
  sorcery
  state_machine
  uglifier (>= 1.3.0)
Run Code Online (Sandbox Code Playgroud)

ill*_*ist 9

如果消息#<Faraday::ConnectionFailed> Connection refused - connect(2)后面跟着 Connection refused - connect(2) for "localhost" port 9200

然后使用命令确保弹性搜索服务是否正在运行

curl localhost:9200

通常,elasticsearch 在端口接收请求9200。如果没有运行,您需要使用命令启动(在 Ubuntu 中) sudo service elasticsearch start。等待几秒钟,然后重试。