在ControllerController中的Errno :: ECONNREFUSED#index错误?对于Elasticsearch和轮胎宝石。如何让我的搜索工作?

时间:2014-11-16 21:01:20

标签: ruby-on-rails elasticsearch tire

我正在尝试搜索我的文章。我正在使用ElasticSearch和Tire gem,试图按照RailsCast#306中的步骤进行操作。 当我尝试搜索时,我收到错误:

Errno::ECONNREFUSED in ArticlesController#index
Connection refused - connect(2)

Extracted source (around line #13):     
 def index
    if params[:query].present?
    @articles = Article.search(params[:query]).paginate(page: params[:page])
else
    @articles = Article.paginate(page: params[:page])
end

如何解决此问题?

这是我的文章模型:

class Article < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
has_many :comments
has_many :taggings
has_many :tags, through: :taggings
mount_uploader :picture, PictureUploader
self.per_page = 4
def tag_list
self.tags.collect do |tag|
tag.name
end.join(", ")
end
def tag_list=(tags_string)
tag_names = tags_string.split(",").collect{|s| s.strip.downcase}.uniq
new_or_found_tags = tag_names.collect { |name| Tag.find_or_create_by(name: name) }
self.tags = new_or_found_tags
end
def picture_size
if picture.size > 5.megabytes
errors.add(:picture, "should be less than 5MB")
end
end
WillPaginate.per_page = 4
end

这是我的文章控制器:

 class ArticlesController < ApplicationController
  before_filter :require_login, except: [:show, :index]
 def index
    if params[:query].present?
    @articles = Article.search(params[:query]).paginate(page: params[:page])
else
    @articles = Article.paginate(page: params[:page])
end
 #@articles = Article.paginate(page: params[:page])
  #@articles_by_month = Article.find(:all).group_by { |post| post.created_at.strftime("%B") }
  @posts = Article.order("created_at DESC")
 end
def show
  @article = Article.find(params[:id])
  @comment = Comment.new
 @comment.article_id = @article.id
end
def new
 @article = Article.new
end
def create
 @article = Article.new(article_params)
 @article.save
 redirect_to article_path(@article)
end
def edit
 @article = Article.find(params[:id])
end
def destroy
 @article = Article.find(params[:id])
 @article.destroy
 redirect_to articles_path
end
def update
 @article = Article.find(params[:id])
 @article.update(article_params)
 flash.notice = "Article '#{@article.title}' Updated!"
 redirect_to article_path(@article)
end

如何让搜索工作? 谢谢!!!

0 个答案:

没有答案