mysql - How to make sure that SQL statement is executed and only then start next code step -


i have strange behaviour when executing ruby code. make new model @user = user.first_or_initialize , @user.save what's strange when after try devise helper method sign_in @user fails because time sql query hasn't been executed. have seen in console. made puts @user.inspect right after sign_in @user. , in terminal i've got unpleasant surprise, puts @user.inspect showed me user model without id means sign_in @user passed user without id. , sql query insert users made after put shown in terminal.

so question, how can lock ruby code execution, until sql statement has executed? when pass @user sign_in passes user model id ???

edit:

@user = user.where(:uid => @shop[:uid]).first_or_initialize  if @user.persisted?   puts 'persisted.'   false else   # new customer   ....     @user.save    sign_in @user end 

i sure record not getting saved , when inspecting record showing initialized copy of object, can use save! see if there exceptions or user.first_or_create!

@user = user.first_or_initialize @user.save! 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -