puts 1.to_s.rjust(3, "0")
#=> 001
puts 10.to_s.rjust(3, "0")
#=> 010
puts 100.to_s.rjust(3, "0")
#=> 100
The above code would convert your user.id into a string, then String.rjust() method would consider its length and prefix appropriate number of zeros.