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 + " = " +
item.to_s
#parametros comunes
@time_entry = TimeEntry.new
userid = User.current.id.to_i
@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,
time1.strftime("%d").to_i).cweek.to_s
@time_entry.user_id = userid
#
horaval = @hora[param_name][index_arr]
@time_entry.hours = horaval #Horas
invertidas
@time_entry.save
last_insert_id = @time_entry.id
log.error "salvado " + index_arr.to_s + ",hora=" +
@hora[param_name][index_arr].to_s + ",idx = " + last_insert_id.to_s
end
end
always returns the first save, I’m doing wrong
Thanks