I am building an invoicing system but cannot use the auto_increment
field to determine the invoice number (because they are running 3
different companies off the one system. I need to find the last
invoice number from any given company and then add 1 to it to get the
next invoice number. BUT, there is a unique case on the very first
invoice produced because there is no earlier invoice number. My
solution is as follows (and does not work)
This is in the ‘create’ controller
if Invoice.find(:all) @temp = Invoice.find_by_sql("select max(inv_number) as inv_number from invoices where company_id = params
@invoice.inv_number = @temp.inv_number +1
The error I am getting is
NoMethodError in Invoices#create
You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.+