Errno :: ECONNREFUSED:连接被拒绝 - 在创建实例时连接(2)

时间:2013-11-20 09:38:23

标签: ruby-on-rails heroku

我刚刚将我的应用程序部署到Heroku,我遇到了一个奇怪的错误。 这是我的Heroku控制台会话重新创建错误: 我有一个公寓对象a:

>> a

=> #<Apartment id: 4, general_description: nil, created_at: "2013-11-20 09:00:05", updated_at: "2013-11-20 09:00:05", landlord_id: 1, bills_included: nil, bills: nil, mcl: nil, accomodation_type: nil, num_bathrooms: nil, booked_complete: nil, floor: nil, elevator: nil, size: nil>

>>a.create_address

   (0.9ms)  BEGIN
  SQL (1.1ms)  INSERT INTO "addresses" ("addressable_id", "addressable_type", "city_id", "created_at", "number", "street", "updated_at", "zipcode") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id"  [["addressable_id", 4], ["addressable_type", "Apartment"], ["city_id", nil], ["created_at", Wed, 20 Nov 2013 09:34:42 UTC +00:00], ["number", nil], ["street", nil], ["updated_at", Wed, 20 Nov 2013 09:34:42 UTC +00:00], ["zipcode", nil]]
   (0.8ms)  ROLLBACK
Errno::ECONNREFUSED: Connection refused - connect(2)

我知道与我的数据库的连接正在工作,因为我能够创建一个用户并签到他。我不知道这个表有什么问题..

另外,如果我这样做:

>> Address.new

我明白了:

=> #<Address id: nil, street: nil, zipcode: nil, number: nil, addressable_id: nil, addressable_type: nil, created_at: nil, updated_at: nil, city_id: nil>

感谢您的所有帮助!

修改

Address.rb

class Address < ActiveRecord::Base
  attr_accessible :number, :street, :zipcode, :city_id
  belongs_to :addressable, polymorphic: true
  belongs_to :city

  include Tire::Model::Search
  include Tire::Model::Callbacks

  def city_name
    city.name
  end

  def to_s
    "#{street} #{number}, #{city_name}, #{city.country_name}"
  end
end

3 个答案:

答案 0 :(得分:4)

您的弹性搜索服务器未运行,您的模型正在尝试连接到弹性搜索搜索。开始对生产进行弹性搜索。

如果您尚未在生产中配置弹性搜索,则必须先将其安装在生产服务器上。

答案 1 :(得分:0)

试试这个添加 https://devcenter.heroku.com/articles/bonsai 并运行

heroku run rake tire:import:all

答案 2 :(得分:0)

我收到此错误,因为我的弹性搜索未运行。这就是我为解决这个问题所做的工作:

第1步: brew信息将为您提供如何启动elacticsearch的选项
$ brew info elacticsearch

步骤2:
$ elasticsearch -f -D es.config = / usr / local / opt / elasticsearch / config / elasticsearch.yml

希望这有帮助。