ruby on rails - How can show the next value from a value saved in a table? -


i'm trying create initial number when user saves initial number of invoice continue next value

table example working:

|invoice_nums|   |id|   |invoice_num|    1        3010 |invoices|   |id|   |invoice_num| |amount|    1        3011         1000    2        3012         1000    3        3013         1000  

table example not working when change invoice_num value invoicenums:

|invoice_nums|   |id|   |invoice_num|    1        2010 |invoices|   |id|   |invoice_num| |amount|    4        2014         1000      ###should 2011    5        2015         1000      ###should 2012  

here controller:

  def new    @num_ini = invoicenum.first    @num_last = invoice.last    @trick = invoice.count(:all)    end 

here view:

<% @sum= "%06d" % (@num.invoice_num.next.to_i + @trick.to_i) %> <%= @sum %> 

i tried in view

<%= @sum= (@num_last.invoice_num.to_i  || @num_ini.invoice_num.to_i )+ 1   %> 

also tried in view:

<% if @num_ini.invoice_num.to_i > @num_last.invoice_num.to_i   %>     <%= @sum= @num_ini.invoice_num.to_i + 1 %> <% else %>     <%= @sum=@num_last.invoice_num.to_i + 1 %> <% end %> 

please can me?

i'm trying continue invoice_num according last invoice_num invoice_nums.

all can accepted.

class invoice < activerecord::base   initial_invoice_number = 2009   before_create :set_invoice_number    def set_invoice_number     (invoice.maximum(:invoice_number) || self::initial_invoice_number) + 1   end  end 

note:

i made initial 2009 because of +1 either or change line trinary condition


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -