Errno::ECONNREFUSED (Connection refused - connect(2))

I am reading " Agile Web Developement with rails". I am using Ruby 1.9.3
and Rails 3.2.16.

I can able to run application locally But application not working on
heroku. I deployed my application successfully on heroku.

When I run rake test, there is no failure.

When I click on place order button i got error like:

We’re sorry, but something went wrong.

I have attached heroku logs and order_controller.rb file. Please find
it.

Output of Heroku logs:

2014-06-20T09:23:11.979417+00:00 app[web.1]:

app/controllers/orders_controller.rb:52:in create' 2014-06-20T09:23:11.979418+00:00 app[web.1]: 2014-06-20T09:23:11.977584+00:00 app[web.1]: Sent mail to [email protected] (8.8ms) 2014-06-20T09:23:11.979414+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)): 2014-06-20T09:23:11.979416+00:00 app[web.1]: app/controllers/orders_controller.rb:56:inblock in

Code of database.yml as follow:

SQLite version 3.x

gem install sqlite3

Ensure the SQLite 3 gem is defined in your Gemfile

gem ‘sqlite3’

development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000

Warning: The database defined as “test” will be erased and

re-generated from your development database when you run “rake”.

Do not set this db to the same as development or production.

test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000

production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000

How can i solve this error?

Kind regards

On 20 June 2014 10:28, Jaimin P. [email protected] wrote:

We’re sorry, but something went wrong.

I have attached heroku logs and order_controller.rb file. Please find
it.

You do not seem to have attached the log, but rather than attach the
whole thing just copy/paste the relevant lines leading up to the
error. You do know that you must use postgres for heroku I hope. If
it is not that then also post database.yml.

Colin

You do not seem to have attached the log, but rather than attach the
whole thing just copy/paste the relevant lines leading up to the
error. You do know that you must use postgres for heroku I hope. If
it is not that then also post database.yml.

I have attached Gemfile, database.yml and heroku logs.doc file. Please
find it.

Please avoid heroku_logs.odt file, if it is not open.

Kind regards

On 20 June 2014 13:12, Jaimin P. [email protected] wrote:

You do not seem to have attached the log, but rather than attach the
whole thing just copy/paste the relevant lines leading up to the
error. You do know that you must use postgres for heroku I hope. If
it is not that then also post database.yml.

I have attached Gemfile, database.yml and heroku logs.doc file. Please
find it.

No you haven’t, at least I cannot see them. Please read my previous
message, just copy/paste the relevant lines of the log. Also
copy/paste database.yml. Gemfile is not required (at least not yet).
Also please confirm that you understand that you must use postgres.

Colin

I have attached Gemfile, database.yml and heroku logs.doc file. Please
find it.

No you haven’t, at least I cannot see them. Please read my previous
message, just copy/paste the relevant lines of the log. Also
copy/paste database.yml. Gemfile is not required (at least not yet).
Also please confirm that you understand that you must use postgres.

I have copy/paste the relevant lines of the log and database.yml.

Kind regards.

On 20 June 2014 14:26, Jaimin P. [email protected] wrote:

I have copy/paste the relevant lines of the log and database.yml.
Well I still don’t see them. When I say copy/paste I mean to copy the
text out of the log or file and paste it into the message before you
send it. So you should be able to see the text in the message.

Also you still have not confirmed that you understand that you must
use postgres.

Colin

On Jun 20, 2014, at 9:58 AM, Jaimin P. [email protected] wrote:

I have used postgres gem in Gemfile which is require to deploy
application to Heroku.

Yet you have specified sqlite as the database adapter.


Scott R.
[email protected]
http://www.elevated-dev.com/
(303) 722-0567 voice

On Jun 20, 2014, at 9:58 AM, Jaimin P. [email protected] wrote:

Yet you have specified sqlite as the database adapter.

Means I should use postgres as the database adapter in development. Is
it correct?

On 20 June 2014 17:17, Jaimin P. [email protected] wrote:

On Jun 20, 2014, at 9:58 AM, Jaimin P. [email protected] wrote:

Yet you have specified sqlite as the database adapter.

Means I should use postgres as the database adapter in development. Is
it correct?

I presume you have worked through Heroku’s guide [1]? If not then do
so. Also work right through a good tutorial such as
railstutorial.org, which is free to use online, and includes setup on
Heroku I believe.

[1] Getting Started with Rails 4.x on Heroku | Heroku Dev Center

Colin

Colin L. wrote in post #1150316:

On 20 June 2014 14:26, Jaimin P. [email protected] wrote:

I have copy/paste the relevant lines of the log and database.yml.
Well I still don’t see them. When I say copy/paste I mean to copy the
text out of the log or file and paste it into the message before you
send it. So you should be able to see the text in the message.

Also you still have not confirmed that you understand that you must
use postgres.

Output of Heroku logs:

2014-06-20T15:56:59.194349+00:00 app[web.1]:Rendered
line_items/_line_item.text.erb (3.6ms)

2014-06-20T15:56:59.206754+00:00 app[web.1]: Sent mail to
[email protected] (10.4ms)

2014-06-20T15:56:59.206917+00:00 app[web.1]: Completed 500 Internal
Server Error in 61.0ms

2014-06-20T15:56:59.194386+00:00 app[web.1]: Rendered
order_notifier/received.text.erb (4.8ms)

2014-06-20T15:56:59.206750+00:00 app[web.1]:
2014-06-20T15:56:59.208468+00:00 app[web.1]:
2014-06-20T15:56:59.208476+00:00 app[web.1]:

2014-06-20T15:56:59.208471+00:00 app[web.1]: Errno::ECONNREFUSED
(Connection refused - connect(2)):

2014-06-20T15:56:59.208474+00:00 app[web.1]:
app/controllers/orders_controller.rb:56:in `block in create’

2014-06-20T15:56:59.208475+00:00 app[web.1]:
app/controllers/orders_controller.rb:52:in `create’

Code of database.yml as follow:

SQLite version 3.x

gem install sqlite3

Ensure the SQLite 3 gem is defined in your Gemfile

gem ‘sqlite3’

development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000

Warning: The database defined as “test” will be erased and

re-generated from your development database when you run “rake”.

Do not set this db to the same as development or production.

test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000

production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000

I have used postgres gem in Gemfile which is require to deploy
application to Heroku.

Kind regards,

You may wish to note that depending if you have Rails 4.0 or 4.1 your
database.yml file may or may not be overwritten by the heroku deploy

Jaimin – what’s on line app/controllers/orders_controller.rb:56 in your
app ?

Whatever apperas on that link created a heroku error Errno::ECONNREFUSED
(Connection refused - connect(2))

(typically that kind of error happens when the rails app is unable to
connect to an external service – like a database or redis, however, as
you can see the exact service is unspecified in this log file example)

Since your issue appears to be a connectivity problem with the Heroku
grid, I suggest you take it up with a support ticket with Heroku
directly.

Typcially for my Heroku deploys I put the config/database.yml file in my
.gitignore so it does not appear in the repository, and let Heroku write
it directly since that mechanism is sure to write out what ever database
you have set in your heroku config variables.

Finally, I would echo what [email protected] said in that Postgres is
the default (and preferred) for Heroku. (Although he is incorrect that
you “must use Postgres” – there are a number of alternative databases
that can be found in the Heroku add-ons page.)

-Jason

On 20 June 2014 17:17, Jaimin P. [email protected] wrote:

I presume you have worked through Heroku’s guide [1]? If not then do
so. Also work right through a good tutorial such as
railstutorial.org, which is free to use online, and includes setup on
Heroku I believe.

[1] Getting Started with Rails 4.x on Heroku | Heroku Dev Center

Thank you for your advise.I will read good tutorial link.

I have used sqlite gem in development group and pg gem in
production group in Gemfile.
.

Could I use in this way?

Kind regards

On Jun 20, 2014, at 12:31 PM, Jaimin P. wrote:

I have sqlite gem in development group and pg gem in production
group.

Could I use in this way?

Yes, but that’s not enough. As Colin pointed out, you still are using
the sqlite3 adapter in your database.yml file. You have to change that
to pg as well, the gems and config have to match.

Walter

On 20 June 2014 17:31, Jason Fleetwood-Boldt [email protected]
wrote:


Finally, I would echo what [email protected] said in that Postgres is the
default (and preferred) for Heroku. (Although he is incorrect that you “must
use Postgres” – there are a number of alternative databases that can be
found in the Heroku add-ons page.)

Thanks for that clarification.

Colin

On Friday, 20 June 2014 23:42:17 UTC-5, Ruby-Forum.com User wrote:

.

I suspect this is the email delivery blowing up - note that you’ll need
to
configure an email service on Heroku.

–Matt J.

On Friday, 20 June 2014 23:42:17 UTC-5, Ruby-Forum.com User wrote:

I suspect this is the email delivery blowing up - note that you’ll need
to
configure an email service on Heroku.

Could I do it by using addons?

Kind regards

Rails 4.1.0 RC1 Support | Heroku Dev Center

Jaimin – what’s on line app/controllers/orders_controller.rb:56 in your
app ?

In orders_controller.rb, line no. 56 as follow:
class OrdersController < ApplicationController
.
.
.
def create
@order = Order.new(params[:order])
@order.add_line_items_from_cart(current_cart)

respond_to do |format|    **# Line no. 52**
  if @order.save
    Cart.destroy(session[:cart_id])
    session[:cart_id] = nil
    OrderNotifier.received(@order).deliver    ** #line number 56 **
    format.html { redirect_to store_url, notice:
      'Thank you for your order.' }
    format.json { render json: @order, status: :created,
      location: @order }

    else
      @cart = current_cart
      format.html { render action: "new" }
      format.json { render json: @order.errors,
         status: :unprocessable_entity }
   end

end
end
.
.
.
end

Kind regards,