Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 法拉第::连接失败,连接被拒绝-connect(2)for“;本地主机&x201D;端口9200错误Ruby on Rails_Ruby On Rails_Ruby_Ruby On Rails 3_Ruby On Rails 4_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 4,elasticsearch" /> elasticsearch,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 4,elasticsearch" />

Ruby on rails 法拉第::连接失败,连接被拒绝-connect(2)for“;本地主机&x201D;端口9200错误Ruby on Rails

Ruby on rails 法拉第::连接失败,连接被拒绝-connect(2)for“;本地主机&x201D;端口9200错误Ruby on Rails,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-4,elasticsearch,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 4,elasticsearch,我试图用Ruby on Rails在我的应用程序中添加Searchkick gem,但当我在搜索框中键入一个单词时,我的应用程序中出现了这个错误。我已经根据需要安装了elasticsearch和最新版本的java,但错误仍然是一样的。这就是我得到的错误: Faraday::PostsController搜索中的连接失败 连接被拒绝-为“localhost”端口9200连接(2) 这是我的密码: 终端显示已安装弹性搜索: 终端 Warning: elasticsearch-1.7.3 alread

我试图用Ruby on Rails在我的应用程序中添加Searchkick gem,但当我在搜索框中键入一个单词时,我的应用程序中出现了这个错误。我已经根据需要安装了elasticsearch和最新版本的java,但错误仍然是一样的。这就是我得到的错误:

Faraday::PostsController搜索中的连接失败

连接被拒绝-为“localhost”端口9200连接(2)

这是我的密码:

终端显示已安装弹性搜索:

终端

Warning: elasticsearch-1.7.3 already installed
posts\u controller.rb

class PostsController < ApplicationController
  before_action :set_post, only: [:show, :edit, :update, :destroy]


def search
  if params[:search].present?
    @posts = Post.search(params[:search])
  else
    @posts = Post.all
  end
end
  # GET /posts
  # GET /posts.json
  def index
    @posts = Post.all
  end

  # GET /posts/1
  # GET /posts/1.json
  def show
  end

  # GET /posts/new
  def new
    @post = Post.new
  end

  # GET /posts/1/edit
  def edit
  end

  # POST /posts
  # POST /posts.json
  def create
    @post = Post.new(post_params)

    respond_to do |format|
      if @post.save
        format.html { redirect_to @post, notice: 'Post was successfully created.' }
        format.json { render :show, status: :created, location: @post }
      else
        format.html { render :new }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /posts/1
  # PATCH/PUT /posts/1.json
  def update
    respond_to do |format|
      if @post.update(post_params)
        format.html { redirect_to @post, notice: 'Post was successfully updated.' }
        format.json { render :show, status: :ok, location: @post }
      else
        format.html { render :edit }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /posts/1
  # DELETE /posts/1.json
  def destroy
    @post.destroy
    respond_to do |format|
      format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_post
      @post = Post.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def post_params
      params.require(:post).permit(:name)
    end
end
class Post < ActiveRecord::Base
  searchkick
end
<p id="notice"><%= notice %></p>

<%= form_tag search_posts_path, method: :get, class: "navbar-form navbar-right", role: "search" do %>
        <p>
          <%= text_field_tag :search, params[:search], class: "form-control" %>
          <%= submit_tag "Search", name: nil, class: "btn btn-default" %>
        </p>
      <% end %>

<h1>Listing Posts</h1>

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th colspan="3"></th>
    </tr>
  </thead>

  <tbody>
    <% @posts.each do |post| %>
      <tr>
        <td><%= post.name %></td>
        <td><%= link_to 'Show', post %></td>
        <td><%= link_to 'Edit', edit_post_path(post) %></td>
        <td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
      </tr>
    <% end %>
  </tbody>
</table>

<br>

<%= link_to 'New Post', new_post_path %>
<table>
  <thead>
    <tr>
      <th>Search Result</th>
      <th colspan="3"></th>
    </tr>
  </thead>

  <tbody>
    <% @posts.each do |post| %>
      <tr>
        <td><%= post.name %></td>
        <td><%= link_to 'Show', post %></td>
        <td><%= link_to 'Edit', edit_post_path(post) %></td>
        <td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
      </tr>
    <% end %>
  </tbody>
</table>
Rails.application.routes.draw do
  resources :posts do
  collection do
    get 'search'
  end
end
end
这是我得到的屏幕,错误如下:

看起来您的弹性搜索服务没有运行。你必须确保它正在运行

要查看弹性搜索服务是否正在运行,请运行:

curl localhost:9200
如果它正在运行,则应返回如下哈希值:

{
  "status" : 200,
  "name" : "Buzz",
  "cluster_name" : "your_cluster_name",
  "version" : {
    "number" : "1.4.5",
    "build_hash" : "...",
    "build_timestamp" : "2015-04-27T08:06:06Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.4"
  },
  "tagline" : "You Know, for Search"
}
如果弹性搜索没有运行(这很可能是您的情况),请使用以下命令启动它:

sudo service elasticsearch start

这应该可以解决您的问题。

sudo服务弹性搜索开始
给我消息“sudo:service:command not found”
sudo service elasticsearch start