I have an Invoices app so that users can create the invoices.
The issue is when I create a New Invoice it's ID is 1 ( http://localhost:3000/invoices/1 ) as this is the first invoice that is Invoice # 1 but when I go to Edit link it still shows ( http://localhost:3000/invoices/1/edit ) but with Invoice # 2, as it must grab the same ID i.e.,1 retaining Invoice # 1.
Here's an screenshot as below;
<div class="col-xs-4"><label>Invoice #</label></div>
<div class="col-xs-8 invoice_num"><span id="invoice_number"><%= (Invoice.last.present? ? (Invoice.last.id + 1) : 1) %></span></div>
If you'r using default rails controller methods for
creating invoices you can use
@invoice instance variable to access it's id when you want to edit an invoice:
<%= @invoice.id %>