Q:

NoMethodError - undefined method `id' for nil:NilClass:

I have a bunch of numbers in a table with parent/child relationships.  I have a column called 'parent_id' that i'm using to match to the parent number's 'id' column.  Issue is, i'm getting a NoMethodError - undefined method `id' for nil:NilClass: when trying to find by 'parent_id'
app.rb
number = Number.find_by_twilio_sid(params[:sid])
forward = Number.find_by_parent_id(number.id)
erb "#{forward.name}"

It gets caught up on the second line when I call the id from the found number.  Here is the terminal response:
NoMethodError - undefined method `id' for nil:NilClass:
/Users/chadsakonchick/Projects/cloud-phone/lib/voice.rb:52:in `block in <top (required)>'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `block in compile!' 
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `[]'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (3 levels) in route!' 
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:985:in `route_eval'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (2 levels) in route!' 
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1006:in `block in process_route'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `catch'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `process_route'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:964:in `block in route!' 
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `each'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `route!' 
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1076:in `block in dispatch!' 
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1073:in `dispatch!' 
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `block in call!' 
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `call!' 
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:886:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/session/abstract/id.rb:225:in `context'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/session/abstract/id.rb:220:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/logger.rb:15:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/commonlogger.rb:33:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:217:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:210:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/head.rb:13:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/methodoverride.rb:22:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:21:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/handler/webrick.rb:89:in `service'
/Users/chadsakonchick/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/Users/chadsakonchick/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/Users/chadsakonchick/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
[2014-11-12 22:44:14] ERROR NoMethodError: undefined method `join' for #<String:0x007fd013edcc28>
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:37:in `rescue in call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:21:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'
/Users/chadsakonchick/.rvm/gems/ruby-2.1.2/gems/rack-1.6.0.beta/lib/rack/handler/webrick.rb:89:in `service'
/Users/chadsakonchick/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/Users/chadsakonchick/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/Users/chadsakonchick/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
localhost - - [12/Nov/2014:22:44:14 CST] "GET /forward/A9R0cadcba83424fdead5602dzQbb83e61 HTTP/1.1" 500 347
- -> /forward/A9R0cadcba83424fdead5602dzQbb83e61

A:

This means there is no entry in you Number table with specified twilio_sid. 
there are multiple method to avoid this error:
One is:
number = Number.find_by_twilio_sid(params[:sid])
forward_name = Number.find_by_parent_id(number.try(:id)).try(:name)
erb "#{forward_name}"

