模特/表不会工作heroku

时间:2012-07-27 17:04:59

标签: ruby-on-rails ruby-on-rails-3 heroku

我正在跟踪使用Rails的Agile Web开发(rails 3.2+),我在第16章,关于部署。但是,我正在跳过大部分b / c我正在计划使用Heroku,我正在试图解决这个问题。无论如何,我昨天成功解密了我的应用程序并且它工作正常,除了我的一个模型。我的'订单'模式总是返回“我们很抱歉,但出了点问题。”错误,我无法弄清楚为什么。这是'heroku logs'

2012-07-27T16:46:00+00:00 app[web.1]: => Booting WEBrick
2012-07-27T16:46:00+00:00 app[web.1]: => Rails 3.2.6 application starting in production on http://0.0.0.0:59115
2012-07-27T16:46:00+00:00 app[web.1]: => Call with -d to detach
2012-07-27T16:46:00+00:00 app[web.1]: => Ctrl-C to shutdown server
2012-07-27T16:46:00+00:00 app[web.1]: Connecting to database specified by DATABASE_URL
2012-07-27T16:46:00+00:00 app[web.1]: [2012-07-27 16:46:00] INFO  WEBrick 1.3.1
2012-07-27T16:46:00+00:00 app[web.1]: [2012-07-27 16:46:00] INFO  ruby 1.9.3 (2012-04-20) [x86_64-linux]
2012-07-27T16:46:00+00:00 app[web.1]: [2012-07-27 16:46:00] INFO  WEBrick::HTTPServer#start: pid=2 port=59115
2012-07-27T16:46:01+00:00 heroku[web.1]: State changed from starting to up
2012-07-27T16:46:04+00:00 app[web.1]: 
2012-07-27T16:46:04+00:00 app[web.1]: Started POST "/en/orders" for 68.110.76.153 at 2012-07-27 16:46:04 +0000
2012-07-27T16:46:04+00:00 app[web.1]: 
2012-07-27T16:46:04+00:00 app[web.1]: Processing by OrdersController#create as HTML
2012-07-27T16:46:04+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"MGaN236tlISbAvzPPHogMMyRPIOux+VjAhjCYv/Uv8g=", "order"=>{"name"=>"Tim Turner", "address"=>"9393 E Thorougbh ", "email"=>"xrobertquinnx@aol.com", "pay_type"=>"Check"}, "commit"=>"Place Order", "locale"=>"en"}
2012-07-27T16:46:05+00:00 app[web.1]:   Rendered collection (0.0ms)
2012-07-27T16:46:05+00:00 app[web.1]:   Rendered order_notifier/received.html.erb (58.4ms)
2012-07-27T16:46:05+00:00 app[web.1]:   Rendered collection (0.0ms)
2012-07-27T16:46:05+00:00 app[web.1]:   Rendered order_notifier/received.text.erb (0.8ms)
2012-07-27T16:46:08+00:00 app[web.1]: 
2012-07-27T16:46:08+00:00 app[web.1]: Sent mail to johndoe@aol.com (3050ms)
2012-07-27T16:46:08+00:00 app[web.1]: 
2012-07-27T16:46:08+00:00 app[web.1]: Completed 500 Internal Server Error in 3619ms
2012-07-27T16:46:08+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)):
2012-07-27T16:46:08+00:00 app[web.1]:   app/controllers/orders_controller.rb:59:in `block in create'
2012-07-27T16:46:08+00:00 app[web.1]:   app/controllers/orders_controller.rb:55:in `create'
2012-07-27T16:46:08+00:00 app[web.1]: 
2012-07-27T16:46:08+00:00 app[web.1]: 
2012-07-27T16:46:08+00:00 heroku[router]: POST depot-app-test.herokuapp.com/en/orders dyno=web.1 queue=0 wait=0ms service=3791ms status=500 bytes=643
2012-07-27T16:46:08+00:00 heroku[router]: GET depot-app-test.herokuapp.com/favicon.ico dyno=web.1 queue=0 wait=0ms service=6ms status=304 bytes=0
2012-07-27T16:46:08+00:00 app[web.1]: [2012-07-27 16:46:08] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

如您所见,存在500内部服务器错误。但是,我不知道是什么原因引起的。我所有的其他型号都运行得很好。这不像是我添加了“订单”模型并且忘记了迁移。我知道'orders'表正在运行,因为我安装了一个sql控制台,我可以看到所有记录的条目。此外,它在当地工作得很好。我也这样做是为了看到更多错误报告:

config.consider_all_requests_local       = true

但是,我没有得到比'heroku logs'更多的信息。任何和所有输入将不胜感激。

修改

订单控制器代码:

class OrdersController < ApplicationController
    skip_before_filter :authorize, only: [:new, :create]

  # GET /orders
  # GET /orders.json
  def index
    @orders = Order.paginate page: params[:page], order: 'created_at desc',
      per_page: 10

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @orders }
    end
  end

  # GET /orders/1
  # GET /orders/1.json
  def show
    @order = Order.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @order }
    end
  end

  # GET /orders/new
  # GET /orders/new.json
  def new
    @cart = current_cart
    if @cart.line_items.empty?
      redirect_to store_url, notice: "Your cart is empty"
      return
    end

    @order = Order.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @order }
    end
  end

  # GET /orders/1/edit
  def edit
    @order = Order.find(params[:id])
  end

  # POST /orders
  # POST /orders.json
  def create
    @order = Order.new(params[:order])
    @order.add_line_items_from_cart(current_cart)

    respond_to do |format|
      if @order.save
        Cart.destroy(session[:cart_id])
        session[:cart_id] = nil
        OrderNotifier.received(@order).deliver
        format.html { redirect_to store_url, notice: 
          I18n.t('.thanks') }
        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

  # PUT /orders/1
  # PUT /orders/1.json
  def update
    @order = Order.find(params[:id])

    respond_to do |format|
      if @order.update_attributes(params[:order])
        format.html { redirect_to @order, notice: 'Order was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @order.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /orders/1
  # DELETE /orders/1.json
  def destroy
    @order = Order.find(params[:id])
    @order.destroy

    respond_to do |format|
      format.html { redirect_to orders_url }
      format.json { head :no_content }
    end
  end
end

2 个答案:

答案 0 :(得分:4)

我认为问题在于您的邮件程序,请尝试使用sendgrid

devcenter.heroku.com/articles/sendgrid#usage

答案 1 :(得分:0)

我在您的错误日志中注意到您正在发送电子邮件,这可能会导致问题。 Heroku不会为您发送电子邮件,因此您需要使用Gmail或获取附加组件。

Heroku电子邮件参考:https://devcenter.heroku.com/articles/smtp

gmail和actionmailer上的Stackoverflow帖子:Setting up a Gmail Account to work with ActionMailer in Rails 3