我有一个运行 Ruby 2.0 的本地机器上的开发模式下完美运行的 rails 4 应用程序。
我最近部署到 Heroku(我对此知之甚少),但我相信这是相同的环境 - 尽管我不知道如何检查。
在任何情况下——它在 Heroku 上也几乎完美地运行,除了一个失败的重定向。(这是 Agile Web Development with Rails 4 中描述的 depot 应用程序)
用户在 example.com/orders/new 下订单后?- 他们被带到 example.com/orders 上的 rails“出了点问题”页面,而不是被重定向到商店主页 url
订单仍然被保存并且可以从管理面板中查看 - 但用户永远不会像在我的本地机器上那样被带回家。有任何想法吗?
订单控制器
class OrdersController < ApplicationController
skip_before_action :authorize, only: [:new, :create]
include CurrentCart
before_action :set_cart, only: [:new, :create]
before_action :set_order, only: [:show, :edit, :update, :destroy]
# GET /orders
# GET /orders.json
def index
@orders = Order.all
end
# GET /orders/1
# GET /orders/1.json
def show
end
# GET /orders/new
def new
if @cart.line_items.empty?
redirect_to store_url, notice: "Your cart is empty"
return
end
@order = Order.new
end
# GET /orders/1/edit
def edit
end
# POST /orders
# POST /orders.json
def create
@order = Order.new(order_params)
@order.add_line_items_from_cart(@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:
'Thank you for your order.' }
format.json { render action: 'show', status: :created, location: @order }
else
format.html { render action: 'new' }
format.json { render json: @order.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /orders/1
# PATCH/PUT /orders/1.json
def update
respond_to do |format|
if @order.update(order_params)
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.destroy
respond_to do |format|
format.html { redirect_to orders_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_order
@order = Order.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def order_params
params.require(:order).permit(:name, :notes, :email, :location)
end
end
编辑 2 (为生产添加邮件配置解决了我的问题 - 但邮件仍未送达) production.rb
config.action_mailer.raise_delivery_errors = false
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
authentication: "plain",
user_name: "my_email_address@gmail.com",
password: "my_password",
enable_starttls_auto: true
}