加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在OrdersController中创建的Errno :: ECONNREF

发布时间:2020-12-17 03:27:55 所属栏目:百科 来源:网络整理
导读:好吧,Rails noob问一个问题.我在这里第一次尝试做Rails.我正在阅读Agile Web Dev with Rails 4th ed.我的生产箱上出现了这个错误. 这在webrick的开发模式下工作,我收到一封电子邮件发送到我的gmail帐户和evrything但是在我的生产模式的apache框中我收到此错
好吧,Rails noob问一个问题.我在这里第一次尝试做Rails.我正在阅读Agile Web Dev with Rails 4th ed.我的生产箱上出现了这个错误.
这在webrick的开发模式下工作,我收到一封电子邮件发送到我的gmail帐户和evrything但是在我的生产模式的apache框中我收到此错误…

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

应用程序跟踪是……

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

这里是app / controllers / order_controller.rb中的def创建

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

我的58号线和54号线出了什么问题?这是否与app / config / environment.rb中的action_mailer设置有关?

这是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

任何帮助表示赞赏.谢谢.

解决方法

我在阅读本书时遇到同样的问题,但以下配置使其有效:

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应用程序.这将为您节省一些不必要的麻烦.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读