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.

How can i solve this error?

Kind regards

Attachments:
http://www.ruby-forum.com/attachment/9823/orders_controller.rb

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

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.

Colin Law wrote in post #1150300:

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.

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

Colin Law wrote in post #1150316:

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
customer@pragmatic.com (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

Yet you have specified sqlite as the database adapter.

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

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] https://devcenter.heroku.com/articles/getting-started-with-rails4

Colin

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

https://devcenter.heroku.com/changelog-items/426

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 clanlaw@gmail.com 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

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

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

Could I use in this way?

Kind regards

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] https://devcenter.heroku.com/articles/getting-started-with-rails4

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

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

Thanks for that clarification.

Colin

https://devcenter.heroku.com/changelog-items/426

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,

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

–Matt Jones

Could I do it by using addons?

Kind regards