我收到此错误消息
金额不能为空
我想根据我认为我创建的金额创建付款before_filter {@amount=Amount.new}
,它不会将创建的金额分配给付款方式。因此,即使在创建新金额后,我的付款仍会出现上述错误。
支付控制器
before_filter {@amount =Amount.new}
def new
@payment = Payment.new
respond_to do |format|
format.html
format.json { render :json => @order }
end
end
def create
@payment = @amount.payments.build(params[:payment])
if @payment.save
if @payment.purchase
render :action=> "success"
else
render :action=> "failure"
end
else
render :action => "new"
end
end
数量控制器
def create
@amount = current_user.amounts.build(params[:amount])
respond_to do |format|
if @amount.save
format.html { redirect_to root_url, :notice => 'Amount was successfully created.' }
format.json { render :json => @amount, :status => :created, :location => @amount }
else
format.html { render :action => "new" }
format.json { render :json => @amount.errors, :status => :unprocessable_entity }
end
end
end
def new
@amount = Amount.new
respond_to do |format|
format.html
format.json { render :json => @amount }
end
end
支付模式
belongs_to :amount
金额模型
has_many :payments