0
사용자가 인보이스에 대한 지불을 입력 할 수있는 양식이 있습니다. 그래서 ...레일즈 3. 유효성 검사 오류시 렌더링
invoice has_many :payments
payment belongs_to :invoice
문제는 유효성 검사 오류가있을 때, 나는이 오류를 얻을 수의 사용자가 요구되는 지불 날짜를 입력하지 않는 가정 해 봅시다입니다 ...
undefined method invoice_number for nil:NilClass
Extracted source (around line #10):
7:
8: <div class="content-box-content">
9: <div class="tab-content default-tab" style="display: block; ">
10: <h4>Invoice #<%= @invoice.invoice_number %> for <%= @invoice.company.name %></h4>
11: <p>Invoice Balance $<%= sprintf("%.2f", @invoice.balance) %></p>
12: </div>
13: </div>
payments_controller.rb
----------------------
def new
@invoice = Invoice.find(params[:invoice_id])
@payment = @invoice.payments.build
respond_to do |format|
format.html
end
end
def create
@payment = Payment.new(params[:payment])
respond_to do |format|
if @payment.save
format.html { redirect_to payments_path, notice: 'Payment was successfully created.' }
else
format.html { render action: "new" }
end
end
end
그래서 render action: "new"
어딘가에서 @invoice를 액션에 추가해야한다는 것을 알고 있습니다. 어떻게해야합니까?
format.html { render action: "new" }
을하기 전에