title: NoMethodError (undefined method `[]' for nil:NilClass): Ruby on Rails even when using dig
body: <p>New to rails and struggling to get my head around this. I am getting this error</p>
  <pre><code>NoMethodError (undefined method `[]' for nil:NilClass):
  </code></pre>
  <p>I am working with the Slack API and there are 2 scenarios depending on whether its a new message or a threaded response. The first is when its a new message, no data is shown in the event attribute</p>
  <p><a href="https://i.stack.imgur.com/mkz8U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mkz8U.png" alt="When its a new message" /></a></p>
  <p>When its a threaded response to a message you can see it does show the event data and I need the tread_ts value.</p>
  <p><a href="https://i.stack.imgur.com/DM45J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DM45J.png" alt="When it's a threaded response" /></a></p>
  <p>Now I know this is quite a common error but I tried a bunch of the suggestions but to be honest, I do not understand what is doing and this is what I came up with but this still throws the method error for line highlighted below:</p>
  <pre><code>json_params = JSON.parse(request.raw_post)
  
  result = json_params.dig(json_params['slack']['event']['ts_thread']) # &lt;-- throwing method error here
  puts result
  </code></pre>
  <p>My understanding from reading other suggested solutions is using .dig should return nil if there is no data but it's not even getting to process that line as it throws the NoMethodError.</p>
  <p>No doubt I have it structured wrong but I would appreciate any guidance. Using rails 6 if that makes a difference</p>