I am trying to get the id of a newly created row in a database table so that I can use it later. But it does not get passed it stays only in the viewer. I need that id after the tab or window is closed. I know there may be other ways of finding that row's id but due to some changes the website will have it needs to be done by using the id.
When the viewer is accessed it goes through a few ruby on rails statements.
<% if user_signed_in? %>
<% @att_record = Attendance.new(:user_id => current_user.id, :time_in => Time.now) %>
<% #@attendance_log = @att_record #tried this already, controller doesn't receive it %>
<%= hidden_field_tag :@get_int, :value => @att_record.id %>
<% @att_record.save %>
It was recommended to me to use hidden_field_tag to get the integer but I can't get it to work.
Its supposed to be able to use the integer once the window is closed. Once the window is closed the following function is executed.
def unload
@get_int
@attendance_log = Attendance.find_by(id: get_int)
@attendance_log.time_out = Time.now
@attendance_log.save
head :ok
end
@att_record is created right there in the views while get_int and attendance_log are created in the unload function.