NoMethodError: undefined method `replies' for nil:NilClass in rails

This error usually happens when we try to access a method of a NilClass. Let say we have a post object like: below:
post = {id: 2}
Now we are trying to access a property called title in the post object like below:
post[:title] #which is nil
Now if we are trying to access a method like below then we will get the error NoMethodError: undefined method for nil
post[:title].replies 
Details on Ruby NilClass can be found in this link

Comments