# Can't convert nil to string error: how to solve?

**URL:** <https://www.ruby-forum.com/t/cant-convert-nil-to-string-error-how-to-solve/135001>\
**Category:** Rails\
**Created:** [April 16, 2008, 11:54pm UTC](https://www.ruby-forum.com/t/cant-convert-nil-to-string-error-how-to-solve/135001 "2008-04-16T23:54:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlesleyball](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jlesleyball](https://www.ruby-forum.com/u/jlesleyball)\
**Post date:** [April 16, 2008, 11:54pm UTC](https://www.ruby-forum.com/t/cant-convert-nil-to-string-error-how-to-solve/135001/1 "2008-04-16T23:54:49Z")

</div>

Hi

What would you say are the top reasons for getting this error? I  
don’t seem to have any of the example cases I’ve found searching with  
Google, and trying to trace through the stack is not giving me any  
clues. Any tips you have for me?

Thanks in advance.

jlb

---

<div class="post-metadata">

**Author:** ![jlesleyball](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jlesleyball](https://www.ruby-forum.com/u/jlesleyball)\
**Post date:** [April 17, 2008, 12:45am UTC](https://www.ruby-forum.com/t/cant-convert-nil-to-string-error-how-to-solve/135001/2 "2008-04-17T00:45:41Z")

</div>

jlesleyball wrote:

> Hi
> 
> What would you say are the top reasons for getting this error? I  
> don’t seem to have any of the example cases I’ve found searching with  
> Google, and trying to trace through the stack is not giving me any  
> clues. Any tips you have for me?
> 
> Thanks in advance.
> 
> jlb

typically caused by  
good\_var + ‘abc’ +  
var\_that\_should\_be\_good\_but\_is\_currently\_nil\_for\_some\_unexpected\_reason

# you prolly want to debug why that var is currently nil for some reason

---

<div class="post-metadata">

**Author:** ![jlesleyball](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jlesleyball](https://www.ruby-forum.com/u/jlesleyball)\
**Post date:** [April 17, 2008, 12:48am UTC](https://www.ruby-forum.com/t/cant-convert-nil-to-string-error-how-to-solve/135001/3 "2008-04-17T00:48:42Z")

</div>

On Thu, 2008-04-17 at 00:45 +0200, Roger P. wrote:

> > jlb
> 
> typically caused by  
> good\_var + ‘abc’ +  
> var\_that\_should\_be\_good\_but\_is\_currently\_nil\_for\_some\_unexpected\_reason
> 
> # you prolly want to debug why that var is currently nil for some reason

* * *

but it may be useful to note that

var\_that\_should\_be\_good\_but\_is\_currently\_nil\_for\_some\_reason.to\_s = ‘’  
instead of nil

Craig
