In sinatra, I am executing this piece of Code containing values in Hash object:
@posts[0]["attachment"]["media"][0]["href"] # where @posts belongs to Koala::Facebook::API::GraphCollection class
works fine in sinatra application, however, the use of a loop:
@posts.each do |post|
post["attachment"]["media"][0]["href"]
end
raises the following error:
undefined method `[]' for nil:NilClass
The error that it displays when executed on command line is :
> NoMethodError: undefined method `[]' for nil:NilClass from
> (irb):12:in `block in irb_binding' from (irb):11:in `each' from
> (irb):11
What am I missing?