Last inserted id

Hi, i have a problem inserting an data in a database

I’m doing a multiple saved in BD touring cycle in each
saved me the id should return the remains, or saved for
insert in the table below.

The problem is that I always return the first id is saved

This is my code

value.each do |item|
if item.to_s != ‘’
log.error “debug post id " + param_name + " = " +
#parametros comunes
@time_entry =
userid =
@time_entry.project_id = @sec
@time_entry.spent_on = current_date
@time_entry.created_on = current_date
@time_entry.updated_on = current_date
@time_entry.activity_id = 8 #valor fijo
@time_entry.tyear = time1.strftime(”%Y")
@time_entry.tmonth = time1.strftime("%m")
@time_entry.tweek =
Date.civil(@time_entry.tyear, @time_entry.tmonth,
@time_entry.user_id = userid
horaval = @hora[param_name][index_arr]

                 @time_entry.hours            =  horaval #Horas



                 last_insert_id =
                 log.error  "salvado " + index_arr.to_s + ",hora=" +

@hora[param_name][index_arr].to_s + ",idx = " + last_insert_id.to_s

always returns the first save, I’m doing wrong


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs