In my model i have the following bit of code.
hash_values = JSON.parse(question_hash)
hash_values.each do |k,v|
b = UpdateData.new
b.question, b.answer, b.phase = v[0].to_i, v[1], v[2].to_i
b.save!
end
I have a problem of phase value. b.phase has an id of 0 to 5 and it also should be null. When the data is not entered for the phase the value is ""(.to_i = 0) it considered as 0 in database. I need to store an null value rather than 0 if phase value is "".
Try: