# Ruby: TypeError: no implicit conversion of nil into String

**Code:** `TypeError: no implicit conversion of nil into String` · **Category:** Ruby / Rails · **Seen on:** Ruby

A String method (`+`, `File.join`, `Array#join` usage) received `nil` instead of a string.

## Meaning

Typically an env var or attribute is `nil` (`ENV["X"] + "/path"`, `"a" + user.name`). Use string interpolation (`"#{x}"`), `to_s`, or `ENV.fetch("X")` to fail clearly. The backtrace line shows the operation.

## Common causes

- `ENV["VAR"]` unset
- `nil` attribute concatenated with `+`
- `File.join` with nil segment
- Missing default in config
- Optional value from params

## Quick fix

1. `ENV.fetch("VAR")` to fail early or `ENV.fetch("VAR", "default")`
2. Use interpolation `"#{name}"` or `name.to_s`
3. Guard against nil with `||`

## Detailed fix by platform

### Ruby

1. `path = File.join(ENV.fetch("APP_ROOT"), "tmp")`

## How to diagnose

1. **Value** — Nil where?
2. **ENV** — Set?
3. **Operation** — Concatenation?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/ruby/typeerror-no-implicit-conversion-of-nil-into-string)
