このエラーメッセージが表示されます
金額は空白にできません
作成した金額に基づいて支払いを作成したいのですが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