Errno::ECONNREFUSED in ArticlesController#index error ? for Elasticsearch and tire gem. How do I get my search to work?

136 views Asked by At

I am trying to include a search for my articles. I am using ElasticSearch and Tire gem, trying to follow the steps in RailsCast #306. When I try to search, I get the error:

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

How do I solve this issue ?

Here is my Articles model:

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

And here is my Articles controller:

 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

How do I get the search to work ? Thanks !!!

0

There are 0 answers