我正在关注使用 Rails 进行敏捷 Web 开发(rails 3.2+),我在第 16 章,关于部署。但是,我计划使用 Heroku 的大部分 b/c 都跳过了它,我目前正在尝试解决这个问题。无论如何,我昨天成功地解散了我的应用程序,它运行良好,除了我的一个模型。我的“订单”模型总是返回“我们很抱歉,但出了点问题”。错误,我不知道为什么。这是'heroku日志'
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 内部服务器错误。但是,我不知道是什么原因造成的。我所有的其他模型都工作得很好。这不像我添加了“订单”模型而忘记了迁移。我知道“订单”表正在工作,因为我安装了一个 sql 控制台,我可以看到所有正在记录的条目。此外,它在本地工作得很好。我也这样做是为了查看更多错误报告:
config.consider_all_requests_local = true
但是,我没有得到比“heroku 日志”中更多的信息。任何和所有输入将不胜感激。
编辑
订单控制器代码:
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