Ruby: undefined method `x` for `nil:nilclass` error

Example:

nil.some_method
This error occurs when you attempt to call a method on a nil object.

Solution:

unless object.nil?
  object.some_method
end

Beginner's Guide to Ruby