Problem: Seemlingly at random, you've encountered the error undefined method `to_sym' for nil:NilClass, or a similar error message for any method name other than to_sym.
Solution: This problem can be a tough one to solve, and there's more than one cause. The reason why you're seeing this message is always the same: the object you're trying to work with is the nil object. The nil object represents nothing. Why is this object nil? More often than not, it's one of two reasons.
- A variable wasn't initialized. If you use a variable without it being initialized, it will return nil. This is especially true with instance variables, where they don't have to be assigned to before they can be referred to. Read back through your code and make sure all your variables are initialized.
- The value nil was returned from a method. Some methods, when they fail to perform their task for some reason, don't raise an exception. It's just not appropriate for all methods to do this. Instead, they'll often return nil. If this is the case, find which method is returning nil and try to determine why it's doing this.