Errno :: ECONNREFUSED in OrdersController # create

OK, Rails noob asks a question. I am trying to do Rails for the first time here. I am reading Agile Web Dev with Rails 4th ed. I get this error in my box. This works in development mode under webrick, I get an email sent to my gmail and evrything account, but in my apache field in production mode I get this error ...

Errno::ECONNREFUSED in OrdersController#create
Connection refused - connect(2)

Application Trace ...

app/controllers/orders_controller.rb:58:in `create'
app/controllers/orders_controller.rb:54:in `create'

And so def create in app / controller / order_controller.rb

def create
@order = Order.new(params[:order])
@order.add_line_items_from_cart(current_cart)

respond_to do |format|  #THIS IS LINE 54
  if @order.save
    Cart.destroy(session[:cart_id]) 
    session[:cart_id] = nil 
    Notifier.order_received(@order).deliver     #THIS IS LINE 58
    format.html { redirect_to(store_url, :notice => I18n.t('.thanks')) }
    format.xml  { render :xml => @order, :status => :created, :location => @order }
  else
    format.html { render :action => "new" }
    format.xml  { render :xml => @order.errors, :status => :unprocessable_entity }
  end
end

What happened to my lines 58 and 54? Is this related to my action_mailer settings in app / config / environment.rb?

Here is environment.rb

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
Depot::Application.initialize!

#uncertain about anything below this line

Depot::Application.configure do 
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address    => "smtp.gmail.com",
    :port       => 587,
    :domain     => "gmail.com",
    :authentication => "plain",
    :user_name  => "myemail@gmail.com",
    :password   => "<password>",
    :enable_starttls_auto => true
}
end

Any help is appreciated. Thank.

+5
source share
2 answers

, :

config.action_mailer.smtp_settings = {
  enable_starttls_auto: true,
  address: 'smtp.gmail.com',
  port: 587,
  authentication: 'plain',
  user_name: 'myemail@gmail.com',
  password: '<password>'
}

, smtp_settings.

, , rails . .

+5

, @Edgar , YAML smtp, symbolize_keys!:

email_settings = YAML::load(File.open("#{Rails.root.to_s}/config/email.yml"))
config.action_mailer.smtp_settings = email_settings[Rails.env].symbolize_keys! unless email_settings[Rails.env].nil?

Rails , , 3 ...

+2

All Articles