Why am i seeing 'undefined method for nil:nilclass' error?


  user = nil
  puts user.name

This is a common Ruby error when you try to call a method on a nil object. Make sure the object is properly initialized and isn't nil before calling methods on it.

  user = User.new
  puts user.name unless user.nil?

Beginner's Guide to Ruby