0

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?

Apoorv Saxena
  • 4,086
  • 10
  • 30
  • 46
  • 2
    not all posts have attachments? – Slartibartfast Apr 23 '12 at 22:44
  • @Slartibartfast Thanks a ton for helping me out.. Just a silly mistake caused me to uninstall my ruby and use different versions of ruby using rvm(but it was good to start using RVM) and search various forums... Thanks again!!! – Apoorv Saxena Apr 24 '12 at 06:38

0 Answers0