undefined method `value' for nil:NilClass #20

dzelle opened this Issue Jul 11, 2012 · 9 comments


None yet

2 participants

dzelle commented Jul 11, 2012


I'm trying to use metainspector to grab meta data in a rails app. I consistently get the following when trying page.image or page.description. It works, however, in the rails console. Below is the trace.

metainspector (1.9.0) lib/meta_inspector/scraper.rb:127:in block in method_missing' nokogiri (1.5.3) lib/nokogiri/xml/node_set.rb:239:inblock in each'
nokogiri (1.5.3) lib/nokogiri/xml/node_set.rb:238:in upto' nokogiri (1.5.3) lib/nokogiri/xml/node_set.rb:238:ineach'
metainspector (1.9.0) lib/meta_inspector/scraper.rb:126:in method_missing' metainspector (1.9.0) lib/meta_inspector/scraper.rb:29:indescription'
app/models/twitter_job.rb:38:in find_or_create' app/models/twitter_job.rb:15:inblock in stories_pull'
app/models/twitter_job.rb:13:in each' app/models/twitter_job.rb:13:instories_pull'
app/models/twitter_job.rb:5:in pull' app/controllers/stories_controller.rb:14:infetch_stories'
app/controllers/stories_controller.rb:7:in pull' actionpack (3.2.2) lib/action_controller/metal/implicit_render.rb:4:insend_action'
actionpack (3.2.2) lib/abstract_controller/base.rb:167:in process_action' actionpack (3.2.2) lib/action_controller/metal/rendering.rb:10:inprocess_action'
actionpack (3.2.2) lib/abstract_controller/callbacks.rb:18:in block in process_action' activesupport (3.2.2) lib/active_support/callbacks.rb:425:in_run__2007603356777030170__process_action__3443411133637203251__callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in __run_callback' activesupport (3.2.2) lib/active_support/callbacks.rb:385:in_run_process_action_callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack (3.2.2) lib/abstract_controller/callbacks.rb:17:inprocess_action'
actionpack (3.2.2) lib/action_controller/metal/rescue.rb:29:in process_action' actionpack (3.2.2) lib/action_controller/metal/instrumentation.rb:30:inblock in process_action'
activesupport (3.2.2) lib/active_support/notifications.rb:123:in block in instrument' activesupport (3.2.2) lib/active_support/notifications/instrumenter.rb:20:ininstrument'
activesupport (3.2.2) lib/active_support/notifications.rb:123:in instrument' actionpack (3.2.2) lib/action_controller/metal/instrumentation.rb:29:inprocess_action'
actionpack (3.2.2) lib/action_controller/metal/params_wrapper.rb:205:in process_action' activerecord (3.2.2) lib/active_record/railties/controller_runtime.rb:18:inprocess_action'


@dzelle I'd like to reproduce this issue, what version of ruby are you using? Could you pass me an example rails app where I can see how you're using MetaInspector there?

@dzelle dzelle closed this Jul 11, 2012
@dzelle dzelle reopened this Jul 11, 2012
dzelle commented Jul 11, 2012

ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]

url = tweet.urls.first.expanded_url
page = MetaInspector::Scraper.new(url)

story = Story.find_or_initialize_by_url(page.url)

return false unless story.new_record?  

#we need
story.title = page.title
story.image = page.image
story.image_urls = page.images
story.owner_comment = tweet.text
story.link_id = nil
story.summary = page.description
story.created_time = nil

story.category = Category.find_by_id(Category.find_category(page.url,  story.title, story.summary, story.owner_comment))

story.users << user

It only happens with page.image and page.description. Would you like more code or runnable code, or I can help in any other way? Thanks.

Sorry, I accidently hit close.

dzelle commented Jul 11, 2012

Adding 'and element.attributes["content"]' to line 127 seems to fix the error, but I do not know if this is correct.


Thanks @dzelle, I'll have a look.

Can you pass me some URLs that are failing with this? Or does it fail with every URL?


OK, I can confirm the bug, it's happening also running it from irb.

I'll work on that, thanks for the feedback.

dzelle commented Jul 12, 2012

Thanks. I will try to contribute as well, if I can track down the bug/have time.


I can't reproduce any error with http://philadelphia.foobooz.com/ ... it returns a description, and no image as the page does not define og:image anywhere. It does return images, though.

I can confirm the bug with youtube, I'm working on a fix.


@dzelle I've released version 1.9.2 of the gem, that fixes this problem. Feel free to reopen this issue if you find more errors on other URLs.

Thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment